We use Google Analytics and PostHog to see which pages bring in customers and where visitors get stuck. Until you agree both run without cookies — they count the pages you open and what you click, but cannot recognise you across visits. Agreeing lets them use cookies, so we can tell repeat visitors apart, lets PostHog record a replay of your visit, with anything you type hidden, and loads OpenAI’s measurement pixel, which shows us whether a visit came from one of our ads in ChatGPT. Nothing is sent to OpenAI until you agree. Either way we never build advertising profiles or target ads. Privacy Policy

15% off your first purchase with code WELCOME15, up to 25 GB.

See pricing

Guide · Scraping practice

502 Bad Gateway or 503 through a proxy: did the proxy or the website send it, and should you retry?

A 502 Bad Gateway or 503 Service Unavailable through a proxy comes from one of two places, and for an HTTPS URL you can tell which. If the error names the proxy or the tunnel (curl's CONNECT tunnel failed, response 503, requests' Tunnel connection failed: 503 Service Unavailable, httpx.ProxyError), the proxy answered before any connection to the site existed. If you got an ordinary response with status 502 or 503, the website or its CDN sent it through the tunnel, because the proxy cannot write into the encrypted stream. Node is the exception: https-proxy-agent, which axios uses, replays the proxy's refusal as a normal response, so Request failed with status code 503 can be either. Both codes are worth a few retries with backoff on a new connection. If the same 502 comes back on every attempt for one hostname, stop and check the hostname and port.

Reviewed 14 Nov 2026

The short answer

  • For HTTPS URLs: an exception that mentions the proxy or the tunnel is the proxy's answer; a response object with status 502 or 503 is the site's. Reproduced with curl, requests, httpx and aiohttp.
  • curl shows both numbers: -w '%{http_connect} %{http_code}' printed 503 000 when the proxy refused the tunnel and 200 502 when the site failed behind a working tunnel.
  • In Node, axios 1.21.1 and got 16.2.0 (via https-proxy-agent) reported a proxy's CONNECT 503 with the same text as a site's 503. undici names the proxy: Proxy response (503) !== 200 when HTTP Tunneling.
  • urllib3's Retry honours Retry-After only on responses. The same 503 with Retry-After: 5 meant 15 seconds of waiting as a response and none at all as an answer to CONNECT.
  • Plain http:// URLs have no tunnel, so a proxy's 503 arrives as a normal response. Compare headers such as Server to see who sent it.

What 502 and 503 mean

RFC 9110 defines 502 Bad Gateway as a server "acting as a gateway or proxy" that "received an invalid response from an inbound server", and 503 Service Unavailable as a server that is temporarily unable to handle the request, for example from overload or maintenance, which "MAY send a Retry-After header field". Any hop can send either one: the proxy, a CDN in front of the site, or the site's own load balancer.

What a particular proxy puts behind each code is its own choice. Our local test proxy answered CONNECT with 502 when the target hostname did not resolve, a second test proxy answered everything with 503 and Retry-After: 5, and a local HTTPS site returned 502 and 503 itself. The tables below come from those three.

Who sent it: the proxy or the site

Reproduced on 2026-11-14. The middle column is the proxy refusing CONNECT for https://example.com/; the right column is a 502 from the HTTPS site behind a working tunnel.

Client (version run)Proxy refused the tunnelSite answered 502 through the tunnel
curl 8.7.1, -w '%{http_connect} %{http_code}'curl: (56) CONNECT tunnel failed, response 503, exit 56, 503 000Exit 0, 200 502
Python requests 2.34.2ProxyError('Unable to connect to proxy', OSError('Tunnel connection failed: 503 Service Unavailable'))No exception, r.status_code == 502
httpx 0.28.1httpx.ProxyError: 503 Service UnavailableNo exception, status 502
aiohttp 3.14.5ClientHttpProxyError: 503, message='Service Unavailable', url='http://127.0.0.1:28084'No exception, status 502
axios 1.21.1, proxy option or https-proxy-agent 9.1.0AxiosError: Request failed with status code 503, err.response.status 503AxiosError: Request failed with status code 502: the same form
got 16.2.0 + https-proxy-agent 9.1.0HTTPError: Request failed with status code 503 (Service Unavailable): GET https://example.com/HTTPError: Request failed with status code 502 (Bad Gateway): GET https://...
undici 7.30.2 fetch + ProxyAgentTypeError: fetch failed, cause Proxy response (503) !== 200 when HTTP TunnelingNo exception, res.status === 502
Chrome 157 and Chromium 156net::ERR_TUNNEL_CONNECTION_FAILED, see that guideNot tested here

Why the Node rows look alike: when the proxy answers CONNECT with anything but 200, https-proxy-agent closes the proxy socket and replays the proxy's buffered answer onto a fake socket "so that the node core http can parse and handle the error status code", as its source comment says. Your code then sees the proxy's 503 as a response for the site's URL. To tell them apart, repeat the request with curl and read %{http_connect}, or use undici, which reports the proxy's status separately. requests, curl and the other Python clients are covered in more detail in requests ProxyError and CONNECT tunnel failed.

Plain http:// URLs: no tunnel, so compare the headers

For an http:// URL the client sends the whole request to the proxy, and the proxy's 502 or 503 comes back as the response itself. curl exited 0 with %{http_connect} = 000 and %{http_code} = 503; requests, httpx and aiohttp returned status 503 without an exception. The response is the only clue: our test site sent Server: test-origin, while the proxy's 503 carried just Retry-After, Content-Length and Connection. Compare the headers and body with a request that works.

If the site offers it, request the https:// URL instead: the tunnel separates the proxy's answers from the site's.

Retrying 502 and 503 without making it worse

urllib3's Retry honours Retry-After by default for 413, 429 and 503, but only on responses. A refused CONNECT reaches it as an exception, so the header is never read. Measured with Retry(total=3, status_forcelist=[502, 503]) against our 503 proxy:

SetupRequests the proxy receivedTimeResult
https:// URL, proxy refuses CONNECT, backoff_factor=040.0 s: Retry-After ignoredProxyError ... Tunnel connection failed: 503 Service Unavailable
http:// URL, proxy's 503 is the response, backoff_factor=0415.0 s: waited 5 s three timesRetryError ... (Caused by ResponseError('too many 503 error responses'))
https:// URL, proxy refuses CONNECT, backoff_factor=146.0 s: 0 + 2 + 4 s of backoffProxyError

So for tunnel failures, backoff is all you get: set backoff_factor, or a proxy that asks you to wait gets the retries at once. urllib3 sleeps backoff_factor * 2 ** (n - 1) seconds and skips the sleep before the first retry, which matches the 0 + 2 + 4 s we measured.

A retry needs a new connection to reach a different exit. With a test proxy that failed every other connection, urllib3 retried the 502 on a new connection and got 200; the next two calls reused the open tunnel and sent no new CONNECT. On a rotating proxy rotation happens per connection, and with a sticky session a new _session- handle draws a new exit (rotating vs sticky sessions).

Cap it at three attempts with backoff, then log and move on. A 502 that returns on every attempt for one hostname is not load: our proxy answered 502 to a misspelled hostname every time. The 429 guide adds jitter and per-host limits.

Code

Worked example

One curl call shows who answered
curl -sS -o /dev/null \  -w 'proxy answered CONNECT with %{http_connect}, site answered %{http_code}\n' \  -x "http://USERNAME_pool-arcfast_country-de:PASSWORD@proxy.arcproxies.io:8000" https://example.com/# Reproduced locally on 2026-11-14, curl 8.7.1:# proxy refused:  curl: (56) CONNECT tunnel failed, response 503#                 proxy answered CONNECT with 503, site answered 000# site failed:    proxy answered CONNECT with 200, site answered 502
requests: retry with backoff, and keep proxy and site failures apart (ran)
import requestsfrom requests.adapters import HTTPAdapterfrom urllib3.util import RetryPROXY = "http://USERNAME_pool-arcfast_country-de:PASSWORD@proxy.arcproxies.io:8000"session = requests.Session()retry = Retry(total=3, backoff_factor=1, status_forcelist=[502, 503, 504], allowed_methods=["GET", "HEAD"])session.mount("http://", HTTPAdapter(max_retries=retry))session.mount("https://", HTTPAdapter(max_retries=retry))try:    r = session.get("https://example.com/", proxies={"http": PROXY, "https": PROXY}, timeout=30)    print("status", r.status_code)except requests.exceptions.ProxyError as err:    print("the proxy refused the tunnel:", err)    # e.g. Tunnel connection failed: 503 Service Unavailableexcept requests.exceptions.RetryError as err:    print("the site kept answering 5xx:", err)     # came through the tunnel, not from the proxy# Ran locally: ProxyError after 6.0 s against a proxy answering 503,# RetryError ('too many 502 error responses') after 6.1 s against a site answering 502,# status 200 through a proxy that failed the first connection only.

FAQ

Questions

Something not covered? Write to contact@arcproxies.io.

Does a 502 through a proxy mean the proxy is down?

Not necessarily. A 502 means some gateway got an invalid response from the server behind it. If your client reports it as a tunnel or proxy error, the proxy sent it, often because it could not reach the target. If it arrives as a normal response to an https:// URL, the website or its CDN sent it.

How do I know if a 503 came from the proxy or the website?

For https:// URLs, run curl with -w '%{http_connect} %{http_code}'. 503 000 means the proxy refused the tunnel; 200 503 means the site answered 503 through it. In Python, a ProxyError is the proxy and a response with status 503 is the site.

Why does axios say Request failed with status code 503 when the site works?

With a proxy, axios tunnels through https-proxy-agent, which replays the proxy's refusal of the CONNECT request as an ordinary response. The 503 may come from the proxy. Check the same URL with curl and %{http_connect}, or use undici, which reports Proxy response (503).

Should I retry 502 and 503 errors through a proxy?

Yes, a few times: up to three attempts with exponential backoff, on a new connection so a rotating proxy can pick another exit. Stop if the same error returns every time for one hostname, and honour Retry-After when the site sends it.

Does requests honour Retry-After from the proxy?

Only when the proxy's 503 is a response, which happens for http:// URLs. When the proxy refuses the CONNECT for an https:// URL, urllib3 treats it as a connection error and retried immediately in our test, so set backoff_factor.

Next

Where to go from here

Use caseProxies for web scraping and data collectionA second provider that just works — Scrapy, requests, Crawlee or Playwright, self-serve, no sales call, bandwidth that never expires.Use caseProxies for price and competitor monitoringSee the price a shopper in Berlin, Lyon or Chicago sees. ISP bandwidth at our lowest price per GB for HTML checks, residential where a marketplace is strict.Guiderequests ProxyError: Max retries exceededrequests.exceptions.ProxyError hides the real cause in its last line. Each variant we reproduced: 407, Connection refused, RemoteDisconnected, SSL.Guidecurl: (56) CONNECT tunnel failed, response 407curl: (56) CONNECT tunnel failed, response 407 means the proxy rejected your credentials. The fix, and how the same 407 looks in requests, httpx and axios.GuideFix ERR_TUNNEL_CONNECTION_FAILEDnet::ERR_TUNNEL_CONNECTION_FAILED means the proxy refused Chrome's CONNECT. The causes we reproduced in Chromium 156, and the Playwright fix.GuideHandling 429 rate limitsWhat HTTP 429 means, how to read Retry-After, and how to retry politely with exponential backoff, jitter and per-host concurrency limits. With code.GuideRotating vs sticky sessionsRotating proxies change exit IP per connection; sticky sessions hold one IP for a set time. How each works, when to use which, and how to set them up.GlossaryRotating proxyA rotating proxy is a proxy endpoint that automatically assigns a different exit IP address from a pool to new connections or requests, so one client's traffic is spread across many addresses without the client managing a list.Free toolProxy testerExit IP, location, latency per phase, rotation and header anonymity for one proxy, or a quick ping of a long list.