python - 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')))
谢谢, 亚特里克
解决方案
我认为您需要在 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/
推荐阅读
- vb.net - 为什么 vb.nets '=' 运算符以这种方式评估不同的类型?
- tensorflow - 如何协调 TFP 与 PyMC3 MCMC 结果?
- android - 应用程序在模拟器上运行良好,但应用程序无法通过 apk 包安装在移动设备上
- javascript - Javascript不适用于asp.net MVC中多选下拉列表的onchange事件
- amazon-web-services - 无法创建 AWS Cognito 身份池
- postgresql - 在plpgsql中,返回没有强制转换的复合类型集?
- html - 如何左对齐一组复选框?
- laravel - Laravel Ajax url 未指向公用文件夹
- python - 如何将消息从 aiohttp 服务发送到 SQS-queue?
- vim - 文本换行到vim的下一行后带有额外缩进的奇怪格式