无法在 python 请求上使用代理

Cant use proxy on python request

我测试了三个版本:在不同机器上的 3.10.2、3.9.9 和 3.8.10,甚至还有一个在线编译器。在所有这些中,我做了以下操作:

import requests
requests.get(url, proxies=proxies, headers=headers)

各参数测试: url:

"https://www.icanhazip.com"
"http://www.icanhazip.com"

代理:

{"https": "223.241.0.250:3000", "http": "223.241.0.250:3000"}
{"https": "223.241.0.250:3000", "http": "223.241.0.250:3000"}

headers:

{'User-Agent': 'Chrome'}
{"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"}

在除 3.10.2 以外的所有版本中,我都遇到了这个错误:

ProxyError: HTTPSConnectionPool(host='www.icanhazip.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', NewConn
ectionError('<urllib3.connection.HTTPSConnection object at 0x05694F40>: Failed to establish a new connection: [WinError 10060] A connection attempt failed beca
use the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond')))

在 3.10.2 上我得到了:

InvalidURL: Proxy URL had no scheme, should start with http:// or https://

但是当我尝试像这样放置代理时: {"https": "223.241.0.250:3000", "http": "223.241.0.250:3000"} 它没有用,它只是显示我的正常 ip。

我错过了什么?一个正常的请求工作得很好,但是当我添加代理时,它就不起作用了。这段代码前一段时间运行良好,现在输出这个错误,我不明白为什么。

尝试在代理地址中添加方案

{"https": "http://223.241.0.250:3000", "http": "http://223.241.0.250:3000"}
{"https": "http://223.241.0.250:3000", "http": "http://223.241.0.250:3000"}