Docs menu
Docs · Error guide

Proxy Error 502 Bad Gateway and 504 Gateway Timeout

A 502 Bad Gateway means a proxy or gateway got an invalid response from the server it forwarded your request to, and a 504 Gateway Timeout means it got no response in time; in both cases your request reached a middle server, and the failure is behind it. Through a proxy, that "server behind it" is either the exit node or the target website, so test the target without the proxy and from another exit IP, then retry with back-off and a longer timeout. ProxyField moves traffic to the next node when one slows down, runs at a 99.6% success rate according to our service data, and you can try it with the Easy Trial: 1 GB for $2.95.

residential IPs
412M+
from, traffic never expires
$1.95/GB
Easy Trial
1 GB for $2.95
gate.proxyfield.io:7000
502 on ProxyField
502 on ProxyFieldProxyField value
When the gateway sends itthe location in the username is well formed, but no exit could be connected
Status line502 Bad Gateway
Text it returns"ProxyField: temporary error. Try again in a few seconds."
City with no exitno fallback to a nearby city: the gateway answers 502
Costa connection the gateway refuses (407, 402, 502) costs nothing
Failover"If a node slows down, traffic automatically moves to the next one."
Sticky sessionon a connection error the gateway retries once with a new session, so the IP may change
SOCKS5a failed exit is reply 0x04, not a 502
The gateway's own responses407, 402 and 502; a 403 from the site itself is passed through
Gatewaygate.proxyfield.io:7000 with your username and password; HTTP, HTTPS and SOCKS5 on the same host and port
Username<login>-country-us-city-new_york: names in lowercase with underscores; the full city list per country is in your dashboard

What to change

  1. Try again in a few seconds; with rotation, the retry leaves through a new IP.
  2. Check the region and city names against the list in your dashboard (lowercase, underscores for spaces).
  3. If the city has no exit right now, widen the username to the region or the country, as in <login>-country-us.
  4. If the body does not carry the ProxyField text above, load the target without the proxy to see whether the site is failing.
  5. Run one request with -v and read the status line and text.

The test, with the login in curl's -U option:

Shell
curl -v -x gate.proxyfield.io:7000 -U "<login>-country-us-city-new_york:<password>" https://api.ipify.org

What a 502 means in general: 502 Bad Gateway (MDN).

On this page 7 sections

What 502 and 504 mean

Both codes are sent by a server acting as a gateway or proxy (RFC 9110, sections 15.6.3 and 15.6.5):

CodeRFC 9110 meaningIn plain words
502 Bad GatewayThe gateway "received an invalid response from an inbound server it accessed while attempting to fulfill the request"The server behind it answered, but with something broken, or dropped the connection
504 Gateway TimeoutThe gateway "did not receive a timely response from an upstream server it needed to access"The server behind it didn't answer before the timeout

MDN's 502 page and 504 page give the same definitions. Neither code says your request was wrong: a 5xx is a server-side failure.

Who sent the 502 or 504?

When you scrape through a proxy, there can be several gateways in a row: your proxy, then a CDN in front of the website, then the website's own load balancer. Any of them can send a 502 or 504.

What you seeWho sent itLikely cause
The website's or CDN's error page (for example a Cloudflare 502/504 page)A gateway in front of the websiteThe website's server is down, overloaded or slow
A 502/504 in your proxy provider's format, or an empty body, on many different targetsThe proxyThe exit node failed or could not reach the target
A 502/504 on one target only, from every exit IPThe website's sideThe site is down or refuses connections
A client-side timeout (ReadTimeout, ETIMEDOUT) with no status codeNobody answeredYour own timeout is shorter than the target needs

For Cloudflare, its 502/504 page says the error means Cloudflare could not establish contact with the website's server, and that most come from that server. On ProxyField, the gateway's own answer when no exit could be connected for the location in your username is 502 Bad Gateway, with the text ProxyField: temporary error. Try again in a few seconds.

How to fix a 502 Bad Gateway through a proxy

  1. Retry once, from a new IP. On per-request rotation, the retry already leaves through another exit node; a one-off 502 from a dropped node is gone on the second try. ProxyField: "If a node slows down, traffic automatically moves to the next one."
  2. Load the target without the proxy. If it fails there too, the website is down; wait.
  3. Check a different target through the same proxy, for example https://api.ipify.org. If that works, the proxy is fine and the target is failing.
  4. Check the protocol and scheme. An https:// proxy URL for a plain HTTP proxy, or HTTP sent to a SOCKS5 port, can come back as a 502 or a broken connection. ProxyField's gateway is gate.proxyfield.io:7000 for HTTP, HTTPS and SOCKS5 alike.
  5. Slow down if 502s rise with your volume. A site that is struggling under load answers bursts with 502s; fewer parallel requests help it and you.

How to fix a 504 Gateway Timeout

  1. Raise your timeouts to fit the target. Slow pages, search pages and large files need more time. Set separate connect and read timeouts so a dead proxy fails fast and a slow page still loads.
  2. Retry with back-off, on a new IP for rotating sessions.
  3. Choose an exit location near the target. A US site served through an exit on another continent adds round-trip time to every request. ProxyField targets country, region and city.
  4. Lower concurrency on one site. A 504 that appears only at high volume means the target, or your machine, is saturated.
  5. Check the target without the proxy. If it is slow everywhere, the timeout is on the site's side.

This Python requests example sets a short connect timeout and a longer read timeout, and retries 502, 503 and 504 with back-off through the ProxyField gateway:

Python
import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry

PROXY = "http://<login>-country-us-city-new_york:<password>@gate.proxyfield.io:7000"

retry = Retry(
    total=4,
    backoff_factor=1.5,                  # waits grow 1.5 s, 3 s, 6 s ...
    status_forcelist=[502, 503, 504],
    allowed_methods=["GET", "HEAD"],
    respect_retry_after_header=True,
    raise_on_status=False,               # return the last response instead of raising
)
s = requests.Session()
s.mount("http://", HTTPAdapter(max_retries=retry))
s.mount("https://", HTTPAdapter(max_retries=retry))
s.proxies.update({"http": PROXY, "https": PROXY})

r = s.get("https://example.com/", timeout=(10, 60))  # (connect, read) in seconds
print(r.status_code)

The Retry options are documented in urllib3. Retry only idempotent requests such as GET; a retried POST can submit twice.

502 vs 503 vs 504

CodeMeaningRetry?
500 Internal Server ErrorThe server itself failedLater; it's the site's bug
502 Bad GatewayA gateway got an invalid answer from the server behind itYes, soon, from a new IP
503 Service UnavailableThe server is overloaded or in maintenanceYes, after Retry-After if given
504 Gateway TimeoutA gateway got no answer in timeYes, with a longer timeout

The 503 case has its own page: Proxy Error 503 Service Unavailable. A connection that fails before any status code is a different problem: see why is my proxy not working.

Prevent proxy timeouts

  • Set explicit connect and read timeouts in every client; library defaults can be "wait forever".
  • Retry with exponential back-off and a cap, on idempotent requests only.
  • Rotate exit IPs between retries, and keep sticky sessions only as long as a task needs them (30 s to 36 h on ProxyField).
  • Target exit locations close to the website.
  • Watch error rates per target; a rising share of 502/504 on one site means slow down, not push harder.

Proxy Error 502 Bad Gateway and 504 Gateway Timeout FAQ

What is a 502 Bad Gateway proxy error, and how do I fix it?

ProxyField runs at a 99.6% success rate, according to our service data, and a 502 Bad Gateway proxy error means a gateway got an invalid answer from the server behind it. To fix it, retry once from a new exit IP, then load the target without the proxy: if the retry works, an exit node failed, and if the site fails everywhere, it is down and you wait.

Is a 504 error always a proxy issue?

No. Any gateway on the way can send it, including a CDN or load balancer in front of the website, and most 504s come from a slow or overloaded target. Test the URL without the proxy to tell which side is slow.

What is the difference between a 502 and a 504 proxy error?

A 502 means the server behind the gateway answered with something invalid or dropped the connection. A 504 means it didn't answer before the gateway's timeout.

Does a 502 error mean I did something wrong?

Usually not: 5xx codes are server-side failures. The exceptions are a wrong proxy scheme or port, which can break the connection to the proxy, and request bursts that overload a fragile site.

How long does a 502 Bad Gateway error last?

A 502 from one failed exit node is gone on the next request with a new IP. A 502 from the website lasts until its server recovers, which can take seconds or hours.

Can proxies help prevent 502 errors when scraping?

Rotating proxies help with 502s from a single failed exit, because the retry leaves through another one. They can't fix a website whose own server is failing.

Is HTTP 502 retryable?

Yes, for idempotent requests such as GET: retry with back-off, on a new IP when you rotate. Don't blindly retry POST requests, which may already have been processed.

How do I prevent proxy timeouts?

Set explicit connect and read timeouts, retry with back-off, pick exit locations near the target and keep concurrency per site moderate. A short connect timeout catches a dead proxy fast while a longer read timeout lets slow pages finish.

What does a proxy timeout error mean?

Something on the path didn't answer in time: the proxy, the exit node or the website. A 504 means a gateway timed out waiting; a client-side timeout with no status code means your own limit ran out first.

Can Cloudflare show a 504 Gateway Timeout?

Yes. Cloudflare shows 502 and 504 pages when it can't get an answer from the website's server, and its documentation says most of them come from that server. Your proxy isn't involved; wait and retry.

Show 3 more questionsShow fewer questions

Does refreshing the page fix a 502 error?

Sometimes, when the cause was a brief overload or a dropped connection. If it persists after a few minutes, the site's server or gateway has a lasting problem.

Can DNS problems cause a 502 Bad Gateway error?

Yes: a gateway that can't resolve the server behind it may answer 502 or 504. When the proxy itself can't be resolved, you get a DNS error instead, covered in the unknown proxy server doc.

How do I fix 502 Bad Gateway and 504 Gateway Timeout errors when my requests go through a proxy?

Retry with back-off from a new exit IP, give slow targets a longer read timeout, and load the target without the proxy to see which side fails. On ProxyField, a 502 Bad Gateway with the text "ProxyField: temporary error. Try again in a few seconds." means the location in your username is well formed but no exit could be connected, so retry or widen a city to its region or country. A connection the gateway refuses (407, 402, 502) costs nothing.

Easy Trial: 1 GB for $2.95.

Try for the price of 1 GB, no subscription, traffic never expires.