What a 502 Bad Gateway means
Think of the gateway or proxy as a receptionist who passes your request to a back office. A 502 means the receptionist got the message through to the back office (the "upstream" server) but the reply came back broken or unreadable. So the failure happens between the edge (the front-facing server) and the origin (the real backend) — not in your request. Because it's a 5xx error, it's a server-side problem and usually clears up on its own.
Why scrapers see 502
When scraping, a 502 usually points to something flaky on the path to the site: an unreliable proxy, an origin server that's overloaded, or a CDN (content delivery network — the cache layer that fronts many sites) that can't reach the backend. It can also show up briefly when an anti-bot edge mishandles or drops a request it finds suspicious. Unlike a 403 (which is a hard "access denied"), a 502 is generally worth retrying.
How to fix a 502 error
Retry with exponential backoff and jitter — that means waiting a bit longer between each attempt and adding a small random delay so retries don't all hit at once. Most 502s clear on their own. If they persist, the gateway between you and the origin is the real problem: swap to a more reliable proxy pool, lower concurrency (fewer requests at once) so you're not overwhelming a fragile origin, and check whether your proxy provider — not the target site — is the one returning the 502. Persistent 502s that only appear on protected URLs can mean an edge is dropping you; in that case a real-browser unblock flow via Web Access API is more stable.