Python 请求不适用于 https 代理

Mrs*_*Ton 3 python https proxy python-requests

我尝试在 python 中使用 https 代理,如下所示:

proxiesDict ={
  'http':  'http://' + proxy_line,
  'https': 'https://' + proxy_line
}


response = requests.get('https://api.ipify.org/?format=json', proxies=proxiesDict, allow_redirects=False)
Run Code Online (Sandbox Code Playgroud)

proxy_line是从 ip:port 格式的文件中读取的代理。我在浏览器中检查了这个 https 代理,它可以工作。但在 python 中,这段代码挂起几秒钟,然后我得到异常:

HTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: /?format=json (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x0425E450>: Failed to establish a new connection: [WinError 10060] 
Run Code Online (Sandbox Code Playgroud)

我尝试使用socks5代理,它适用于安装了PySocks的socks5代理。但是对于 https 我遇到了这个异常,有人可以帮助我吗

cs9*_*s95 5

为 指定代理列表时requests,键为协议,值为域/ip。您不需要指定http://或https://对于实际值,

所以,你的proxiesDict意愿是:

proxiesDict = {
  'http':  proxy_line,
  'https': proxy_line
}
Run Code Online (Sandbox Code Playgroud)