首页 > 解决方案 > urllib3.ProxyManager 给出身份验证错误

问题描述

我正在尝试使用 urllib3.ProxyManager 发送 https 请求。我的代码看起来像这样

default_headers = urllib3.util.make_headers(proxy_basic_auth='user:passwd')
http = urllib3.ProxyManager(proxyUrl, headers=default_headers, ca_certs=certifi.where())
http.request('GET', url)

我得到以下错误 -

MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='clinicaltrials.gov', port=443): Max retries exceeded with url: /ct2/results?term=Lilly&displayxml=true&count=5000 (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required')))

谢谢, 亚特里克

标签: pythonproxyurllib3

解决方案


我认为您需要在 ProxyManager 中设置 proxy_headers,而不是标头:

default_headers = urllib3.util.make_headers(proxy_basic_auth='user:passwd')
http = urllib3.ProxyManager(proxyUrl, proxy_headers=default_headers, ca_certs=certifi.where())
http.request('GET', url)

请参阅文档中的 urllib3.poolmanager.ProxyManager:https ://urllib3.readthedocs.io/en/latest/reference/


推荐阅读