简体   繁体   English

无法似乎使用Python请求使https和袜子代理工作

[英]Cant seem to get https and socks proxies to work using python requests

So I'm looking at traffic using wireshark and comparing the output for a number of situations. 因此,我正在使用Wireshark查看流量,并比较多种情况下的输出。 I'm only looking at traffic between me and google.co.za. 我只看我和google.co.za之间的流量。

Situation 1: Accessing google.co.za using no proxy 情况1:不使用代理访问google.co.za

requests.get('www.google.co.za')

This returns a response with status=200 and wireshark displays info about traffic passing between my pc and google's servers. 这将返回状态为200的响应,wireshark显示有关在我的PC和Google服务器之间传递的流量的信息。 This is great so far. 到目前为止很好。

Situation 2: Accessing google.co.za using valid http proxy 情况2:使用有效的http代理访问google.co.za

requests.get("http://google.co.za",proxies={'http':proxy})

This returns a response with status=200 and wireshark displays no data about traffic passing between my pc and google's servers. 这将返回状态为200的响应,wireshark 不会显示有关在我的PC和Google服务器之间传递的流量的数据。 This is great and expected and stuff. 这是伟大的,期望和东西。

Situation 3: Accessing google.co.za using valid socks proxy 情况3:使用有效的袜子代理访问google.co.za

requests.get("http://google.co.za",proxies={'socks':proxy})

result as per situation 1. Hmmm 根据情况1的结果。

Situation 4: same deal with https 情况4:与https处理相同

requests.get("http://google.co.za",proxies={'https':proxy})

same result as situation 1. 与情况1相同的结果。

Question

So it looks like when I try to use https and socks proxies requests acts as though the proxy argument is empty. 因此,当我尝试使用https和socks proxies请求时,好像proxy参数为空。 Now I need to pass traffic through all sorts of proxies and I don't want any silent failures. 现在,我需要通过各种代理传递流量,并且我不希望出现任何静默故障。

My question is: Why is stuff failing silently and what can I do to fix it? 我的问题是:为什么东西会无声地失败,我该怎么办才能解决?

Requests simply does not yet support either SOCKS or HTTPS proxies. Requests根本不支持SOCKS或HTTPS代理。

They're working in it, though. 他们正在努力。 See here: https://github.com/kennethreitz/requests/pull/1515 看到这里: https : //github.com/kennethreitz/requests/pull/1515

Support for HTTPS proxies has already been merged into the requests 2.0 branch, so if you like you can try that version; 对HTTPS代理的支持已经合并到requests 2.0分支中,因此,如果您愿意,可以尝试使用该版本。 be wary though, as it it is currently an unstable branch. 但是要小心,因为它目前是一个不稳定的分支。

SOCKS proxy support, on the other hand, is still being worked on in the lower-level library, urllib3 : https://github.com/shazow/urllib3/pull/68 另一方面,SOCKS代理支持仍在底层库urllib3https : //github.com/shazow/urllib3/pull/68

Also, regardless of that, you are using the proxies argument incorrectly. 此外,无论如何,您都错误地使用了proxies参数。 It should be of the form {protocol_of_sites_you_visit: proxy} , so once support is complete, using a SOCKS5 proxy would actually be more along the lines of {"http": "socks5://127.0.0.1:9050"} . 它的格式应为{protocol_of_sites_you_visit: proxy} ,因此一旦完成支持,使用SOCKS5代理实际上将更像{"http": "socks5://127.0.0.1:9050"}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM