python auth_error ai_generated true

requests.exceptions.ConnectionError: HTTPConnectionPool(host='proxy.example.com', port=8080): 超过最大重试次数 (由ProxyError('无法连接到代理。', OSError('隧道连接失败:407 代理身份验证必需'))引起)

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

其他格式: JSON · Markdown 中文 · English
80%修复率
87%置信度
0证据数
2024-03-10首次发现

版本兼容性

版本状态引入弃用备注
3.x active

根因分析

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

English

The proxy requires authentication credentials, but none were provided.

generic

解决方案

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

无效尝试

常见但无效的做法:

  1. Setting the proxy URL without credentials 95% 失败

    The proxy server explicitly rejects connections without authentication.

  2. Using an environment variable HTTP_PROXY without authentication 90% 失败

    Environment variables also need credentials if the proxy requires them.