请求库不正确地通过代理来引导HTTP请求

我知道如何使用requests ,但由于某种原因,我没有成功地让代理工作。 我正在提出以下要求:

 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 

然而,我知道代理工程,因为使用节点:

 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中做错了什么?

正如sigmavirus24所说,这是一个已知的问题 ,已经被修复,但还没有被打包成一个新的版本,并推送到PyPI。

所以,如果你急着需要这个,你可以从git仓库的主人那里升级。

如果你使用pip ,这很简单。 而不是这个:

 pip install -U requests 

做这个:

 pip install -U git+https://github.com/kennethreitz/requests 

如果你不使用pip ,你可能需要明确地git clone repo,然后easy_install . 或者python setup.py或者你的本地副本。

这是一个已知的问题: https : //github.com/kennethreitz/requests/issues/1074

我不确定为什么它需要这么长时间才能解决。 要回答你的问题,你没有做错什么。