What to change
- Try again in a few seconds; with rotation, the retry leaves through a new IP.
- Check the region and city names against the list in your dashboard (lowercase, underscores for spaces).
- If the city has no exit right now, widen the username to the region or the country, as in
<login>-country-us. - If the body does not carry the ProxyField text above, load the target without the proxy to see whether the site is failing.
- Run one request with
-vand read the status line and text.
The test, with the login in curl's -U option:
curl -v -x gate.proxyfield.io:7000 -U "<login>-country-us-city-new_york:<password>" https://api.ipify.orgWhat 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):
| Code | RFC 9110 meaning | In plain words |
|---|---|---|
| 502 Bad Gateway | The 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 Timeout | The 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 see | Who sent it | Likely cause |
|---|---|---|
| The website's or CDN's error page (for example a Cloudflare 502/504 page) | A gateway in front of the website | The website's server is down, overloaded or slow |
| A 502/504 in your proxy provider's format, or an empty body, on many different targets | The proxy | The exit node failed or could not reach the target |
| A 502/504 on one target only, from every exit IP | The website's side | The site is down or refuses connections |
A client-side timeout (ReadTimeout, ETIMEDOUT) with no status code | Nobody answered | Your 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
- 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."
- Load the target without the proxy. If it fails there too, the website is down; wait.
- 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. - 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 isgate.proxyfield.io:7000for HTTP, HTTPS and SOCKS5 alike. - 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
- 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.
- Retry with back-off, on a new IP for rotating sessions.
- 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.
- Lower concurrency on one site. A 504 that appears only at high volume means the target, or your machine, is saturated.
- 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:
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
| Code | Meaning | Retry? |
|---|---|---|
| 500 Internal Server Error | The server itself failed | Later; it's the site's bug |
| 502 Bad Gateway | A gateway got an invalid answer from the server behind it | Yes, soon, from a new IP |
| 503 Service Unavailable | The server is overloaded or in maintenance | Yes, after Retry-After if given |
| 504 Gateway Timeout | A gateway got no answer in time | Yes, 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.