【发布时间】:2020-09-08 11:47:52
【问题描述】:
我正在尝试使用高级代理 IP 连接到使用请求模块的网站,但它不适用于“https”网站。
import requests
from requests.auth import HTTPProxyAuth
auth=HTTPProxyAuth('username','password')
proxies={
'http':'http://xxx.xxx.x.xxx:8080/',
'https':'http://xxx.xxx.x.xxx:8080/'
}
print(requests.get('https://www.google.com',proxies=proxies,auth=auth).status_code)
抛出以下错误:
raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='www.google.com',port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required')))
注意:我已经尝试使用各种猴子补丁,这些补丁甚至从 7 年前就建议进行 Digest Auth,但它们似乎都不起作用。
编辑 1:
我没有使用 http://username@password:ip:port/ 格式来使用代理,因为我的用户名包含“@”,这会导致解析错误。
提前致谢:)
【问题讨论】:
标签: python python-3.x https proxy python-requests