---
title: "Proxy Error Codes: What 407, 502, 503 and 504 Mean"
description: "A proxy error code says who failed: the proxy or the site. What 400, 403, 407, 429, 502, 503, 504 and SOCKS5 replies mean, and the first fix for each."
url: https://proxynet.io/blog/proxy-error-codes
date: 2026-11-30
author: "Acar Diveroli"
category: "Tutorial, Proxies"
lang: en
---

# Proxy Error Codes: What 407, 502, 503 and 504 Mean

Your script ran fine all morning, and now the log fills with `CONNECT tunnel failed, response 502`. A colleague's browser shows a 403, a monitoring job reports 504, and someone asks whether "the proxy is down". The status code alone does not answer that. The same three digits can come from the proxy you pay for, from a proxy on your own network or from the website at the end of the line, and each case has a different fix.

This page is a reference for anyone who sends traffic through a proxy. It starts with the question that saves the most time, who wrote the error, then covers 400, 403, 407, 429, 502, 503 and 504, the failures that arrive without a status code and the SOCKS5 reply codes. A diagnostic flow with one `curl -v` example and a Python retry function close it. We reproduced every error on 28 November 2026 with a test proxy and a test web server on our own machine (curl 8.23, Python 3.13, Requests 2.34); the outputs below come from those runs.

> **Note: Short answer**
>
> A proxy error code is an HTTP status code or a connection error that tells you which hop of the request failed. 407 always comes from a proxy and means it wants credentials. 502 means the proxy could not get a valid answer from the site, 504 means the answer did not arrive in time, and 503 means the proxy or the site is temporarily unable to serve. 400, 403 and 429 can come from either side. An error returned during the `CONNECT` step, or one with a `Proxy-Authenticate` or `Proxy-Status` header, is the proxy's; a response that arrives after `200 Connection established` is the website's. Fix proxy-side errors in your settings, credentials or plan; answer site-side errors on the site's terms, by slowing down or contacting its owner.

## What is a proxy error code?

A proxy error code is the status code, or connection error, you get when a request through a proxy does not end with the page you asked for. Most are ordinary HTTP status codes from [RFC 9110](https://www.rfc-editor.org/rfc/rfc9110.html#section-15), the HTTP standard. What makes them proxy errors is the sender: the proxy writes them when it cannot or will not forward your request.

For an `http://` address your client sends the whole request to the proxy, which fetches the page. For an `https://` address the client first asks the proxy for a tunnel with `CONNECT host:443`; after `200 Connection established`, encrypted traffic flows through and the proxy can no longer read or change it. Some failures have no status code at all: a closed port or a dropped connection leaves nothing to read but a connection error or a timeout. SOCKS5 proxies use their own one-byte reply codes.

## Who sent the error: the proxy or the website?

The stage tells you. RFC 9110 says any 2xx response to `CONNECT` switches the connection to tunnel mode, and any other response means the tunnel was not formed. So a status code you get *instead of* `200 Connection established` comes from a proxy, and one you get *after* it comes from the website.

Four signs help when the stage is not obvious:

1. **The error appears at the tunnel step.** curl prints `CONNECT tunnel failed, response 502`; Python Requests raises `ProxyError` with `Tunnel connection failed: 502 Bad Gateway`. The site never saw the request.
2. **A proxy header is present.** `Proxy-Authenticate` comes only with a 407. `Proxy-Status`, defined in [RFC 9209](https://datatracker.ietf.org/doc/html/rfc9209), is written only by intermediaries, and its `error=` parameter names the problem, such as `connection_refused`.
3. **`Via` is present or missing.** A proxy must add `Via` to each message it forwards. On plain HTTP, the site's own 403 reached us with `Via: 1.1 testproxy`; the proxy's own 504 had no `Via`, only `Proxy-Status`.
4. **The body and `Server` header.** A proxy's error page is short and generic; a site's usually has its own design, a `Server:` value such as `nginx` and often a reference ID.

If doubt remains, send the same request without the proxy. If the error disappears, the proxy hop is involved.

## How does a request through a proxy fail, step by step?

A proxied request passes six checkpoints, and each fails with a typical code:

1. **Your client reaches the proxy.** A wrong host, a closed port or a firewall stops it here, with no status code.
2. **The proxy reads the request.** A request it cannot parse, such as `CONNECT` without a port, gets 400.
3. **The proxy checks who you are.** Missing or wrong credentials, or a source IP not on the whitelist, gets 407.
4. **The proxy checks its rules.** A blocked port or destination gets 403; too many requests for your plan gets 429 or 503, depending on the provider.
5. **The proxy connects to the site.** A refused connection or failed DNS lookup gets 502; no answer in time gets 504.
6. **The site answers.** From here on, every code (200, 403, 404, 429, 500…) is the site's own.

Our test proxy reproduced each stage; steps 1 to 5 ended before any website was contacted.

## Proxy error codes at a glance

| Code | Usually sent by | Common cause | First fix |
|---|---|---|---|
| 400 | Proxy or site | Malformed request or proxy URL | Check URL, scheme and port |
| 403 | Proxy or site | Proxy policy, or the site refuses | Find the sender first |
| 407 | Proxy only | Missing or wrong credentials | Send the right `user:pass` |
| 429 | Proxy or site | Plan limit, or site rate limit | Slow down; honour `Retry-After` |
| 502 | Proxy (or site gateway) | Upstream refused or DNS failed | Check target; retry with backoff |
| 503 | Proxy or site | Overload or maintenance | Wait for `Retry-After` |
| 504 | Proxy (or site gateway) | Upstream too slow | Retry later; raise the timeout |
| No code | Network | Proxy unreachable or silent | Check host, port, firewall |

## What does 400 Bad Request mean through a proxy?

A 400 means the server could not parse the request. Through a proxy the cause is usually on your side: a proxy URL with a missing scheme or a stray space, an unencoded character in the target URL, or a `CONNECT` line without a port, which RFC 9110 tells proxies to reject with 400. Our test proxy did exactly that for `CONNECT example.com HTTP/1.1`. A 400 after the tunnel opened is the site's answer to a bad parameter, cookie or header. In both cases, change the request; retrying it unchanged will not help.

## What does 403 Forbidden mean: the proxy or the site?

A 403 means the server understood the request and refuses it. From the proxy, it is a policy decision: the port is not allowed, a company proxy blocks the domain, or the plan does not include the feature. RFC 9110 advises proxies to limit `CONNECT` to known ports, and our test proxy, which allowed only 443, answered a tunnel to port 8443 with `CONNECT tunnel failed, response 403`.

A 403 from the site arrives through a working tunnel, with the site's own page. The owner decided not to serve this request: the page is private, the site's rules exclude the region or IP, or the traffic looked automated. Read the site's terms, use its official API if there is one, slow down or contact the owner; a site's 403 is not an obstacle to route around.

## What does 407 Proxy Authentication Required mean?

A 407 always comes from a proxy and means it wants credentials before forwarding anything. Its `Proxy-Authenticate` header names the scheme, usually `Basic`. The cause is a username or password that is missing, mistyped or contains an unencoded `@`, or an IP whitelist that no longer matches your address. Our test proxy answered an unauthenticated request with `Proxy-Authenticate: Basic realm="testproxy"`. The [HTTP 407 guide](/blog/http-407-proxy-authentication-required) shows where credentials go in curl, Python, Node.js, Chrome, Git and pip.

## What does 429 Too Many Requests mean on a proxy?

A 429 means too many requests in a given time ([RFC 6585](https://datatracker.ietf.org/doc/html/rfc6585#section-4)), and a `Retry-After` header may say how long to wait. Two different limits produce it. A proxy can cap requests or parallel connections per account; many providers answer 429 above that, while some use 503 or refuse new connections. A site can cap requests per client.

A 429 at the tunnel step is your proxy's limit: lower concurrency or check your plan. A 429 after the tunnel is the site's rate limit: wait at least as long as `Retry-After` says and send fewer requests per second. Switching IPs to keep the same pace ignores the owner's rule; slowing down respects it. Our test proxy allowed five requests per ten seconds, and seven requests in a row returned `200 200 200 200 200 429 429` with `Retry-After: 10`.

## What do 502, 503 and 504 mean on a proxy?

All three are server errors that a proxy can write about its trip to the site; they differ in what went wrong on that trip. The [502 Bad Gateway guide](/blog/502-bad-gateway) covers the site owner's side.

### 502 Bad Gateway

A 502 means the proxy got an invalid answer from the server it contacted, or none at all. RFC 9209 recommends 502 for a refused connection, a failed DNS lookup and a connection closed mid-response. Our test proxy returned `502 Bad Gateway` with `Proxy-Status: testproxy; error=connection_refused` for a closed target port, and `error=dns_error` for a host name that does not exist. Check the host and port, open the URL without the proxy, and retry a few times with growing pauses.

### 503 Service Unavailable

A 503 means the server is temporarily unable to handle the request, because of overload or maintenance. From the proxy, it means no capacity for you right now: maintenance, no upstream available or a connection limit. From the site, the site itself is overloaded. Either way, wait for `Retry-After` and try again; more requests make a 503 last longer.

### 504 Gateway Timeout

A 504 means the proxy waited for the site and the answer did not come in time. Our test proxy waited three seconds for a slow page, then answered `504 Gateway Timeout` with `Proxy-Status: testproxy; error=http_response_timeout`. Usual causes are a slow or overloaded site, a long route or a page that takes long to build. Retry after a pause; if the page is simply slow, raise your client's read timeout.

## Which proxy errors have no status code?

No status code means no HTTP answer arrived, so the failure happened before the HTTP exchange. These are the messages we reproduced:

- **Connection refused.** Nothing listens on the proxy port, or a firewall rejects you. curl: `Failed to connect to example.com:443 over proxy 127.0.0.1 … Could not connect to server` (exit code 7). Requests: `ProxyError … Unable to connect to proxy`.
- **Timeout.** The proxy accepts the connection but never answers. curl with `-m 5`: `Connection timed out after 5003 milliseconds` (exit code 28). Requests: `ReadTimeout`.
- **Could not resolve.** The proxy's host name, or the site's when resolved locally, does not exist: `Could not resolve proxy` (5) or `Could not resolve host` (6).
- **Tunnel failed.** The proxy answered `CONNECT` with an error; curl 8.23 printed `CONNECT tunnel failed, response 403` with exit code 7. The number after `response` is the proxy's status code.

The [libcurl error list](https://curl.se/libcurl/c/libcurl-errors.html) explains each exit code. If a browser shows the same situation as `ERR_PROXY_CONNECTION_FAILED`, the [proxy server not responding guide](/blog/proxy-server-not-responding) walks through the device settings.

## What do SOCKS5 reply codes mean?

A SOCKS5 proxy answers each connection request with a one-byte reply code from section 6 of [RFC 1928](https://www.rfc-editor.org/rfc/rfc1928.html). `0x00` is success; any other value means the proxy could not open the connection and will close it shortly after.

| Code | RFC 1928 meaning | What it usually means |
|---|---|---|
| `0x01` | General SOCKS server failure | Proxy-side problem; retry |
| `0x02` | Not allowed by ruleset | Proxy policy blocks the target |
| `0x03` | Network unreachable | No route to the target network |
| `0x04` | Host unreachable | Host down or name not resolved |
| `0x05` | Connection refused | Nothing listens on that port |
| `0x06` | TTL expired | Attempt timed out on the way |
| `0x07` | Command not supported | BIND or UDP not offered |
| `0x08` | Address type not supported | IPv6 or domain form refused |

Authentication fails before these codes. With no credentials, curl printed `No authentication method was acceptable.`; with a wrong password, `User was rejected by the SOCKS5 server (1 1).` For a refused target, curl 8.23 put the reply code in brackets: `cannot complete SOCKS5 connection to 127.0.0.1. (5)`, exit code 97. Requests with PySocks named it in words: `0x05: Connection refused`. With `socks5h://` the proxy resolves host names and reports a failure as `0x04`; with `socks5://` your machine resolves them, and curl stopped with `Could not resolve host` before reaching the proxy.

## How do you diagnose a proxy error in six steps?

A fixed order finds the cause of most proxy errors in minutes:

1. **Read the exact message:** status code, exit code, and whether it mentions `CONNECT`, `tunnel` or `proxy`.
2. **Run the request with `curl -v`** to see every line the proxy and the site send.
3. **Find the stage:** an error instead of `200 Connection established` is the proxy's; anything after it is the site's.
4. **Read the headers:** `Proxy-Authenticate`, `Proxy-Status` and `Via` name the sender; `Retry-After` gives the wait.
5. **Compare without the proxy:** same error means the site; no error means the proxy hop.
6. **Change one thing at a time:** credentials, then port and scheme, then target, then timeout and concurrency.

The command for step 2 (in Windows PowerShell type `curl.exe` and `-o NUL`):

```bash
curl -v -o /dev/null -x http://pr.proxynet.io:8000 -U user:pass https://httpbin.org/status/403
```

Through our test proxy, the tunnel opened, so the 403 that followed came from the site:

```text
> CONNECT httpbin.org:443 HTTP/1.1
> Proxy-Authorization: Basic dXNlcjpwYXNz
< HTTP/1.1 200 Connection established
* CONNECT tunnel established, response 200
> GET /status/403 HTTP/1.1
< HTTP/1.1 403 Forbidden
```

When the proxy itself refused, its answer replaced the `200` line and carried the reason:

```text
> CONNECT 127.0.0.1:443 HTTP/1.1
< HTTP/1.1 502 Bad Gateway
< Proxy-Status: testproxy; error=connection_refused
* CONNECT tunnel failed, response 502
```

## How do you handle proxy errors in code?

Sort errors into "retry later" and "stop and fix". 429, 502, 503, 504 and timeouts are often temporary and worth a few retries with growing pauses. 400, 403 and 407 from the proxy are not: the same request gets the same answer until you change something. The site's own 4xx answers go back to your code, because only you know whether a 404 is expected.

This Requests function applies those rules. For HTTPS addresses a failed tunnel raises `ProxyError` instead of returning a response, so it reads the status from the message; it honours `Retry-After` when the value is in seconds.

```python
import os
import re
import time

import requests

PROXY = os.environ.get("PROXY", "http://user:pass@pr.proxynet.io:8000")
PROXIES = {"http": PROXY, "https": PROXY}
RETRYABLE = {429, 502, 503, 504}

def wait_time(attempt, retry_after=None):
    # Retry-After in seconds wins; otherwise 2, 4, 8 ... seconds, capped at 60
    if retry_after and retry_after.isdigit():
        return min(int(retry_after), 60)
    return min(2 ** attempt, 60)

def fetch(url, attempts=4):
    for attempt in range(1, attempts + 1):
        try:
            r = requests.get(url, proxies=PROXIES, timeout=(5, 20))
        except requests.exceptions.ProxyError as e:
            # the proxy refused the request or the tunnel: the site never saw it
            m = re.search(r"Tunnel connection failed: (\d{3})", str(e))
            code = int(m.group(1)) if m else None
            if code in (400, 403, 407):
                raise  # bad request, proxy policy or credentials: a retry changes nothing
            print(f"attempt {attempt}: proxy error {code or 'without a status'}")
            delay = wait_time(attempt)
        except requests.exceptions.Timeout:
            print(f"attempt {attempt}: timeout")
            delay = wait_time(attempt)
        else:
            if r.status_code not in RETRYABLE:
                return r  # 2xx, 3xx and the site's own 4xx go back to the caller
            print(f"attempt {attempt}: {r.status_code}, Proxy-Status={r.headers.get('Proxy-Status')}")
            delay = wait_time(attempt, r.headers.get("Retry-After"))
        if attempt < attempts:
            time.sleep(delay)
    raise RuntimeError(f"gave up after {attempts} attempts: {url}")

if __name__ == "__main__":
    r = fetch("https://httpbin.org/ip")
    print(r.status_code, r.text.strip())
```

With three attempts against the test proxy, a tunnel to a closed port printed `proxy error 502` on each of its three attempts and raised `RuntimeError`; a slow page printed `504, Proxy-Status=testproxy; error=http_response_timeout`; missing credentials and a blocked port raised `ProxyError` at once; the site's own 403 came back as a normal response. For `http://` targets Requests returns 407 or 504 as a response rather than an exception, which is why the `else` branch checks the status.

## When does the proxy itself cause errors?

The proxy is the cause when the error comes from its own stage and the request works over another route. A shared IP that others have used heavily can draw 403 or 429 answers sooner than your own traffic would; a distant exit adds latency and makes 504s likelier on slow pages; a low connection limit returns 429 or 503 at the tunnel step.

For legitimate work that keeps meeting the first problem, [Residential Proxy](https://proxynet.io/residential-proxy) gives exits on home connections, country and city targeting to keep the route short, and sticky sessions of 1 to 60 minutes. For tools that speak SOCKS, a [SOCKS5 Proxy](https://proxynet.io/socks5-proxy) carries the same traffic over SOCKS5, UDP included. Neither changes a site's rules: if a site answers 403 or 429 through any IP, follow its terms and slow down.

## Common mistakes

- **Blaming the site for a tunnel error.** `CONNECT tunnel failed` is always the proxy's answer.
- **Blaming the proxy for every 403.** A 403 after `200 Connection established` is the site's decision.
- **Retrying 407 and 403 in a loop.** Credentials and policy do not fix themselves.
- **Ignoring `Retry-After`.** Retrying sooner than asked usually extends the wait.
- **Catching only exceptions.** For `http://` targets, proxy errors arrive as normal responses.
- **Using `socks5://` when the proxy should resolve names.** The local lookup can fail and shows your DNS server every host; use `socks5h://`.

## Decision guide

| What you see | What to do |
|---|---|
| `CONNECT tunnel failed, response 407` | Check username, password, whitelist |
| `CONNECT tunnel failed, response 403` | Check port, destination and plan |
| 403 or 429 after the tunnel opened | Follow the site's limits; slow down |
| 429 or 503 at the tunnel step | Lower concurrency; honour `Retry-After` |
| 502 with `Proxy-Status` | Check target host and port; back off |
| 504 on slow pages | Raise the read timeout; retry later |
| No code, `Could not connect` | Check proxy host, port, firewall |
| SOCKS5 `(2)`, `(4)` or `(5)` | Policy, host or port at the target |

## Frequently asked questions

### What are the most common proxy error codes?

407 (the proxy wants credentials), 502 (no valid answer from the site), 503 (temporarily unavailable), 504 (the answer took too long) and 429 (too many requests). 400 and 403 also appear, from either the proxy or the site.

### How do I know if an error comes from the proxy or from the website?

Look at the stage. An error returned instead of `200 Connection established`, shown by curl as `CONNECT tunnel failed` and by Requests as `Tunnel connection failed`, comes from the proxy; anything after the tunnel opened comes from the site. `Proxy-Authenticate` and `Proxy-Status` headers also point to the proxy.

### What does proxy error code 429 mean?

Too many requests in a short time. At the tunnel step it is your plan's request or connection limit, so lower your concurrency. After the tunnel opened it is the site's rate limit, so wait for `Retry-After` and send fewer requests.

### Is a 502 error my fault or the proxy's?

Usually neither: the site refused the connection, its name did not resolve or it sent an invalid answer. Check the host and port, open the URL without the proxy and retry with pauses. If it works directly but fails through every exit, contact the provider.

### What is the difference between 503 and 504 on a proxy?

A 503 says the proxy or the site cannot take the request right now, often with a `Retry-After`. A 504 says the proxy waited for the site and the answer came too late. Wait and retry a 503; for a 504, retry later or raise your read timeout.

### What does "cannot complete SOCKS5 connection" mean in curl?

The SOCKS5 proxy answered with a failure reply code, which curl prints in brackets: `(2)` ruleset block, `(4)` host unreachable, `(5)` connection refused, as listed in RFC 1928. curl exits with code 97, a proxy handshake error.

## Summary

A proxy error code is most useful once you know who wrote it. Errors that replace `200 Connection established`, carry `Proxy-Authenticate` or `Proxy-Status`, or have no status code belong to the proxy hop; fix them with credentials, ports, timeouts and concurrency. Errors that arrive through an open tunnel belong to the site; answer them on its terms. Retry 429, 502, 503, 504 and timeouts with growing pauses, and stop on 400, 403 and 407 until you have changed something. For proxies with HTTP, HTTPS and SOCKS5 access and username or IP whitelist authentication, see our [proxy services](/proxy).
