python
auth_error
ai_generated
true
requests.exceptions.ConnectionError: HTTPConnectionPool(host='proxy.example.com', port=8080): Max retries exceeded with url: http://target.com/ (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required')))
ID: python/requests-connectionerror-proxy-authentication
80%Fix Rate
87%Confidence
0Evidence
2024-03-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
The proxy requires authentication credentials, but none were provided.
generic中文
代理需要身份验证凭据,但未提供。
Workarounds
-
95% success Include username and password in the proxy URL
proxies = {'http': 'http://user:[email protected]:8080'} requests.get('http://target.com', proxies=proxies) -
90% success Use the requests.auth.HTTPProxyAuth class
from requests.auth import HTTPProxyAuth auth = HTTPProxyAuth('user', 'password') requests.get('http://target.com', proxies={'http': 'http://proxy.example.com:8080'}, auth=auth)
Dead Ends
Common approaches that don't work:
-
Setting the proxy URL without credentials
95% fail
The proxy server explicitly rejects connections without authentication.
-
Using an environment variable HTTP_PROXY without authentication
90% fail
Environment variables also need credentials if the proxy requires them.