urllib3.ProxyManager is giving authentication error

送分小仙女□ 提交于 2020-05-16 23:01:46

问题


I am trying send a https request using urllib3.ProxyManager. My code looks something like this

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)

I am getting below error -

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')))

Thanks, Yatrik


回答1:


I think you need to set proxy_headers, not headers in ProxyManager:

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)

See urllib3.poolmanager.ProxyManager in the docs: https://urllib3.readthedocs.io/en/latest/reference/



来源:https://stackoverflow.com/questions/58131573/urllib3-proxymanager-is-giving-authentication-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!