我知道如何很好地使用请求
,但由于某种原因,我没有成功地让代理工作。我提出以下要求:
r = requests.get('http://whatismyip.com', proxies={'http': 'http://148.236.5.92:8080'})
我得到以下信息:
requests.exceptions.ConnectionError: [Errno 10060] A connection attempt failed b
ecause the connected party did not properly respond after a period of time, or e
stablished connection failed because connected host has failed to respond
但是,我知道代理可以工作,因为使用 Node :
request.get({uri: 'http://www.whatismyip.com', proxy: 'http://148.236.5.92:8080'},
function (err, response, body) {var $ = cheerio.load(body); console.log($('#greenip').text());});
我得到以下(正确)响应:
148.236.5.92
此外,当我以完全不同的方式尝试 requests
请求时(例如,不在代理前面写入 http://
),它只允许请求正常通过,无需通过代理或返回错误。
我在 Python 中做错了什么?
最佳答案
这是一个已知问题:https://github.com/kennethreitz/requests/issues/1074
我不确定为什么要花这么长时间才能修复。不过,回答你的问题,你没有做错任何事。
关于python - 请求库未通过代理正确引导 HTTP 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14348857/