Timeouts and retries
Use a 90 second client timeout and retry 429, 502, 503 and 504 with backoff. Failed requests are never charged.
Most searches return in a few seconds. When eBay pushes back on a search we retry it for you before answering, so an
occasional request takes longer. Use a client timeout of at least 90 seconds, and retry 429, 502, 503 and 504
with a short backoff. Failed requests never count against your allowance, so retrying is free. Do not retry 400,
401 or 402: fix the request or plan first.
import time, requests
RETRY = {429, 502, 503, 504}
def sold(keyword, **params):
for attempt in range(4):
r = requests.get(
"https://api.ebaysoldlistingsapi.com/scrape",
params={"keyword": keyword, **params},
headers={"Authorization": "Bearer YOUR_API_KEY"},
timeout=90,
)
if r.status_code not in RETRY:
r.raise_for_status()
return r.json()
time.sleep(int(r.headers.get("Retry-After", 2 ** attempt)))
r.raise_for_status()