【问题标题】:Python requests module not working with Proxy when trying to access HTTPS sites尝试访问 HTTPS 站点时,Python 请求模块无法与代理一起使用
【发布时间】: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


    【解决方案1】:

    我觉得你可以用这个

    http://username@password:ip:port/
    

    您提到您的密码包含特殊字符

    “@”可以替换为“%40”

    例如,

    “Pass@word”可以替换为“Pass%40word”

    如果您的密码中包含更多特殊字符,以下数据可能会有所帮助

    '@' = '%40'
    '%' ='%25'
    '#' = '%23'
    '@' = '%40'
    ':' = '%3a'
    ';' = '%3b'
    '?' = '%3f'
    '$' = '%24'
    '!' = '%21'
    '/' = '%2f'
    '\' = '%27'
    '"' = '%22'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-23
      • 1970-01-01
      • 1970-01-01
      • 2018-09-23
      • 2020-10-17
      • 2018-12-03
      • 1970-01-01
      相关资源
      最近更新 更多