如何在Windows上使用Putty SOCKS代理使用python请求?

我已经设置腻子创build一个服务器的Socks代理。 我可以使用Chrome和Firefox访问主机。 当我使用请求时,我得到一个错误,似乎表明连接到腻子有问题。 我试图设置HTTP_PROXY envvariables,我试图通过代理参数。 envvariables方法产生“失败parsing”错误,而代理方法产生超过最大重试次数。

设置env在调用requests.get("http://10.122.116.17:8080/")时会产生这个错误

 requests.packages.urllib3.exceptions.LocationParseError: Failed to parse: Failed to parse: "localhost:1088" 

在调用requests.get("http://10.122.116.17:8080/",proxies=proxies)时,传递参数会产生这个错误。

 requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=1088): Max retries exceeded with url: http://10.122.116.17:8080/ (Caused by <class 'httplib.BadStatusLine'>: '') 

我已经安装了Wireshark,并在我的代理服务器上进行筛选,这是在216.255.67.119。 当我运行Firefox时,我看到了这个地址的stream量。 当我运行Python请求时,我看不到任何到服务器的stream量。 所以我怀疑请求中的代理机制没有进入我的Putty会话。

有没有人有任何提示或build议可能发生在这里? 我一直search,直到我的手指受伤!

提前致谢!!!

以下是使用Firefox时服务器的外观

专用服务器上的Tomcat

—————- cmd输出–​​———————–

 C:\Users\patman>set HTTP_PROXY="localhost:1088" C:\Users\patman>echo %HTTP_PROXY% "localhost:1088" C:\Users\patman>set HTTPS_PROXY="localhost:1088" C:\Users\patman>python Enthought Python Distribution -- www.enthought.com Version: 7.3-2 (64-bit) Python 2.7.3 |EPD 7.3-2 (64-bit)| (default, Apr 12 2012, 15:20:16) [MSC v.1500 64 bit (AMD64)] on win32 Type "credits", "demo" or "enthought" for more information. >>> import requests >>> requests.get("http://10.122.116.17:8080/") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python27\lib\site-packages\requests-1.2.0-py2.7.egg\requests\api.py", line 55, in get return request('get', url, **kwargs) File "C:\Python27\lib\site-packages\requests-1.2.0-py2.7.egg\requests\api.py", line 44, in request return session.request(method=method, url=url, **kwargs) File "C:\Python27\lib\site-packages\requests-1.2.0-py2.7.egg\requests\sessions .py", line 346, in request resp = self.send(prep, **send_kwargs) File "C:\Python27\lib\site-packages\requests-1.2.0-py2.7.egg\requests\sessions .py", line 449, in send r = adapter.send(request, **kwargs) File "C:\Python27\lib\site-packages\requests-1.2.0-py2.7.egg\requests\adapters .py", line 263, in send conn = self.get_connection(request.url, proxies) File "C:\Python27\lib\site-packages\requests-1.2.0-py2.7.egg\requests\adapters .py", line 188, in get_connection conn = ProxyManager(self.poolmanager.connection_from_url(proxy)) File "C:\Python27\lib\site-packages\requests-1.2.0-py2.7.egg\requests\packages \urllib3\poolmanager.py", line 122, in connection_from_url u = parse_url(url) File "C:\Python27\lib\site-packages\requests-1.2.0-py2.7.egg\requests\packages \urllib3\util.py", line 156, in parse_url raise LocationParseError("Failed to parse: %s" % url) requests.packages.urllib3.exceptions.LocationParseError: Failed to parse: Failed to parse: "localhost:1088" >>> >>> proxies = { ... "http": "localhost:1088", ... "https": "localhost:1088", ... } >>> requests.get("http://10.122.116.17:8080/",proxies=proxies) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python27\lib\site-packages\requests-1.2.0-py2.7.egg\requests\api.py", line 55, in get return request('get', url, **kwargs) File "C:\Python27\lib\site-packages\requests-1.2.0-py2.7.egg\requests\api.py", line 44, in request return session.request(method=method, url=url, **kwargs) File "C:\Python27\lib\site-packages\requests-1.2.0-py2.7.egg\requests\sessions .py", line 346, in request resp = self.send(prep, **send_kwargs) File "C:\Python27\lib\site-packages\requests-1.2.0-py2.7.egg\requests\sessions .py", line 449, in send r = adapter.send(request, **kwargs) File "C:\Python27\lib\site-packages\requests-1.2.0-py2.7.egg\requests\adapters .py", line 318, in send raise ConnectionError(e) requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=1 088): Max retries exceeded with url: http://10.122.116.17:8080/ (Caused by <clas s 'httplib.BadStatusLine'>: '') >>> requests.__version__ '1.2.0' >>> import urllib3 >>> urllib3.__version__ '1.7.1' >>> 

腻子设置… 在这里输入图像说明

请求目前不支持SOCKS代理。 我们希望得到底层urllib3库的支持,但是没有明确的时间表。 跟踪这个问题 。

在2016年编辑 :截至请求2.10,请求现在支持SOCKS代理。 你可以通过安装socks extra来获得支持: pip install requests[socks]