Guide · Scraping practice
How to fix requests.exceptions.ProxyError: Max retries exceeded
requests.exceptions.ProxyError: ... Max retries exceeded with url is a wrapper. The useful part is the text after Caused by ProxyError(...): Tunnel connection failed: 407 means wrong or missing credentials, Connection refused means nothing is listening on that host and port, Tunnel connection failed: 501 or 502 means the port is not a proxy or the proxy could not reach the site, and an SSLError means the proxy URL starts with https://. "Max retries exceeded" does not mean anything was retried: requests makes one attempt by default. Read the cause, fix that one thing, and check the proxy works with the proxy tester before changing code.
Reviewed 2 Nov 2026
The short answer
- By default requests does not retry failed connections. We counted exactly one CONNECT per call, despite "Max retries exceeded" in the message.
- urllib3 2.x prints
Unable to connect to proxy; urllib3 1.26 printedCannot connect to proxy.. Same error, different wording. - A proxy that closes the connection gives
ConnectionError: ('Connection aborted.', RemoteDisconnected(...))on urllib3 2.x, notProxyError. Missing dependencies for SOCKS supportisInvalidSchema: installrequests[socks].- A mounted
Retrydoes retry a 407 (four CONNECTs withtotal=3), so filter 407 out of your retry logic.
Read the last line: the cause inside the wrapper
Reproduced on 2026-11-02 with Python 3.13.12, requests 2.34.2 and urllib3 2.8.0 against local test proxies, each call requests.get("https://example.com/", proxies={"http": proxy, "https": proxy}). The left column is what follows Caused by in the message.
| Cause in the message | What it means | Fix |
|---|---|---|
ProxyError('Unable to connect to proxy', OSError('Tunnel connection failed: 407 Proxy Authentication Required')) | The proxy rejected or did not get the credentials | Check username and password, URL-encode special characters; see CONNECT tunnel failed, 407 |
ProxyError('Unable to connect to proxy', NewConnectionError("...Failed to establish a new connection: [Errno 61] Connection refused")) | Nothing listening on that host and port (errno 61 on macOS) | Check host and port; ARC's gateway is proxy.arcproxies.io:8000 |
ProxyError('Unable to connect to proxy', OSError("Tunnel connection failed: 501 Unsupported method ('CONNECT')")) | The port belongs to a web server, not a proxy | Use the proxy's port |
ProxyError('Unable to connect to proxy', OSError('Tunnel connection failed: 502 Bad Gateway')) | Proxy is fine but could not reach the target | Check the target hostname; retry later with backoff |
ProxyError('Unable to connect to proxy. Your proxy appears to only use HTTP and not HTTPS...', SSLError(...)) | The proxy URL starts with https:// but the proxy speaks HTTP | Use http://; see SSL: WRONG_VERSION_NUMBER |
ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')) | The proxy accepted the connection, then closed it without answering | Check the port and protocol; retry once, then stop |
ConnectionError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer')) | http:// URL pointed at a SOCKS port | Use socks5h:// (with requests[socks]) or the HTTP port |
InvalidSchema: Missing dependencies for SOCKS support. | A socks5:// or socks5h:// URL without PySocks | pip install "requests[socks]" |
InvalidProxyURL: Please check proxy URL. It is malformed and could be missing the host. | No scheme in the proxy URL | Write http://user:pass@host:port |
"Cannot connect to proxy" vs "Unable to connect to proxy"
The wording comes from urllib3, not requests. We ran the same tests with requests 2.31.0 and urllib3 1.26.20 (Python 3.12.6): every cause above came out as ProxyError('Cannot connect to proxy.', ...), including RemoteDisconnected and ConnectionResetError, which urllib3 2.x reports as a plain ConnectionError instead. If your traceback says "Cannot connect to proxy.", you are on urllib3 1.x and the inner cause still tells you what failed.
With a plain-HTTP target (http://...) there is no tunnel, and a wrong password does not raise at all: requests 2.34.2 returned a response with status_code == 407. Check for that status as well as the exception.
Why it says "Max retries exceeded" when nothing was retried
The message comes from urllib3's MaxRetryError, which requests wraps. requests documents that HTTPAdapter(max_retries=...) defaults to no retries for failed connections, and our test proxy logged one CONNECT per call.
If you mount an adapter with urllib3's Retry, failed tunnels are retried, including a 407 that can never succeed: with Retry(total=3) our proxy logged four CONNECT requests with the wrong password. The Python requests integration has a retry loop that stops on 407.
Checks that solve most cases
- Test the same proxy string in the proxy tester. If it fails there, fix the credentials or the endpoint before touching code.
- Print the environment: requests also reads
HTTP_PROXY,HTTPS_PROXYandALL_PROXY, so a stale variable can override what you think you configured.env | grep -i _proxyshows them. - Map both keys to the same
http://URL. The key is the scheme of the site, the value is how to reach the proxy. - URL-encode special characters in the password (
@as%40,:as%3A). requests 2.34.2 happened to parsep@ss:w0rdunencoded in our test, but curl 8.7.1 refused the same URL, so encode it everywhere. - Compare the exit IP with what is my IP when a request succeeds but seems to bypass the proxy.
Code
Worked example
import requestsfrom requests.exceptions import ProxyError, SSLError, ConnectionError as ConnErrorPROXY = "http://USERNAME_pool-arcfast_country-de:PASSWORD@proxy.arcproxies.io:8000"def root_cause(err: BaseException) -> BaseException: """Walk to the innermost exception behind requests' wrapper.""" seen = err while True: nxt = getattr(seen, "reason", None) if not isinstance(nxt, BaseException): nxt = seen.__cause__ or seen.__context__ if nxt is None and seen.args and isinstance(seen.args[-1], BaseException): nxt = seen.args[-1] if nxt is None or nxt is seen: return seen seen = nxttry: r = requests.get("https://example.com/", proxies={"http": PROXY, "https": PROXY}, timeout=30) print(r.status_code)except (ProxyError, SSLError, ConnError) as err: cause = root_cause(err) print(f"{type(err).__name__} -> {type(cause).__name__}: {cause}") # ProxyError -> OSError: Tunnel connection failed: 407 Proxy Authentication Required # ProxyError -> ConnectionRefusedError: [Errno 61] Connection refused # ConnectionError -> RemoteDisconnected: Remote end closed connection without responserequests.exceptions.ProxyError: HTTPSConnectionPool(host='example.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Unable to connect to proxy', OSError('Tunnel connection failed: 407 Proxy Authentication Required')))requests.exceptions.ProxyError: HTTPSConnectionPool(host='example.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Unable to connect to proxy', NewConnectionError("HTTPSConnection(host='127.0.0.1', port=18099): Failed to establish a new connection: [Errno 61] Connection refused")))requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))# requests 2.31.0 + urllib3 1.26.20, same proxy closing the connection:requests.exceptions.ProxyError: HTTPSConnectionPool(host='example.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response')))FAQ
Questions
Something not covered? Write to contact@arcproxies.io.
What does requests.exceptions.ProxyError Max retries exceeded mean?
requests could not get a working connection through the proxy. The cause is at the end of the message after Caused by: a 407 means wrong credentials, Connection refused means nothing is listening on that host and port, and an SSLError means the proxy URL wrongly starts with https://.
Did requests really retry my request?
Not by default. requests documents that it does not retry failed connections unless you configure max_retries, and our test proxy saw one attempt per call. The words come from urllib3's MaxRetryError.
How do I fix ProxyError Tunnel connection failed: 407?
The proxy rejected the credentials while opening the HTTPS tunnel. Copy the username and password again, URL-encode special characters in the password, and test the same string in a proxy tester. Retrying will not help.
What does Cannot connect to proxy RemoteDisconnected mean?
The proxy accepted the TCP connection and then closed it without answering. On urllib3 1.26 that is reported as ProxyError Cannot connect to proxy; on urllib3 2.x as ConnectionError Connection aborted. Check that the port is the proxy's HTTP port and that the scheme matches.
Why does requests say Missing dependencies for SOCKS support?
The proxy URL uses socks5:// or socks5h:// and PySocks is not installed. Run pip install "requests[socks]". Use socks5h:// so the proxy resolves hostnames.
Should I catch ProxyError and retry?
Only for causes that can change: a 502 or 503 from the proxy, a reset connection or a timeout. A 407, a refused connection or an SSL error from an https:// proxy URL are configuration mistakes and fail the same way every time.
Sources & review
Last reviewed by the ARC Proxies team. Prices are read from the live catalog at build time.
- [1]Requests: Advanced usage: Proxies and SOCKS
- [2]Requests: Developer interface: HTTPAdapter max_retries
- [3]urllib3: Advanced usage: Your proxy appears to only use HTTP and not HTTPS
- [4]urllib3: Changelog (1.26.0: HTTPS proxies; 2.2.0: OpenSSL 3.2 error message)
- [5]IETF: RFC 9110: HTTP Semantics, 15.5.8 407 Proxy Authentication Required
Next
Where to go from here
Guides