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

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
0Evidence
2024-03-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

The proxy requires authentication credentials, but none were provided.

generic

中文

代理需要身份验证凭据,但未提供。

Workarounds

  1. 95% success Include username and password in the proxy URL
    proxies = {'http': 'http://user:[email protected]:8080'}
    requests.get('http://target.com', proxies=proxies)
  2. 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:

  1. Setting the proxy URL without credentials 95% fail

    The proxy server explicitly rejects connections without authentication.

  2. Using an environment variable HTTP_PROXY without authentication 90% fail

    Environment variables also need credentials if the proxy requires them.