如何解决尝试访问HTTPS网站时,Python请求模块无法与Proxy配合使用
我正在尝试使用高级代理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 /格式来使用代理,因为我的用户名包含“ @”,这会导致解析错误。
预先感谢:)
解决方法
我认为您可以使用此
http://username@password:ip:port/
您提到您的密码包含特殊字符
'@'可以替换为'%40'
例如,
“ Pass @ word”可以替换为“ Pass%40word”
如果您在密码中添加了一些特殊字符,则以下数据可能会有所帮助
'@' = '%40'
'%' ='%25'
'#' = '%23'
'@' = '%40'
':' = '%3a'
';' = '%3b'
'?' = '%3f'
'$' = '%24'
'!' = '%21'
'/' = '%2f'
'\' = '%27'
'"' = '%22'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。