如何通过 TOR 和 Privoxy 使用 Python 请求获取 HTTPS 内容
我在我的系统上安装了 TOR 并使用 Privoxy 进行了测试并且运行良好.我想要做的是通过此设置代理 HTTPS 请求,以便这些 GET 和 POST 来自 TOR.以下是我可以生成的代码的最简单版本:
I have TOR setup on my system with Privoxy that has been tested and works well. What I am trying to do is proxy HTTPS requests through this setup, so that these GET and POSTs come through TOR. Below is the simplest version of the code I could produce:
import requests
proxy = { 'http':'127.0.0.1:8118','https':'127.0.0.1:8118' }
r = requests.get('https://www.whatismyip.com/',proxies=proxy)
#r = requests.get('http://www.whatsmyip.org/')
print r
使用 HTTPS 时,我没有收到响应正文(r.content 为空),但我收到了 200 状态代码,我可以在 Privoxy 日志中看到请求发出.我在 this 线程上看到一个错误,但似乎已解决几个月前在请求库中使用 this.
When using HTTPS, I do not get the response body (r.content is blank), but I do get a 200 status code and I can see the request go out in the Privoxy logs. I saw a bug on this thread, but it appears that was solved in the Requests library months ago with this.
我的 privoxy 设置是基本的,并且设置为通过添加以下两行来监听本地主机:
My privoxy setup is the basic one and setup to listen on the localhost with the addition of the following two lines:
forward-socks4a / localhost:9050 .
forward-socks5 / localhost:9050 .
此时我不确定发生了什么,但我所做的一切似乎都不起作用.我在 Python 2.6.5 上使用最新的请求库和 urllib3.
At this point I am not sure what's going on, but nothing I do seems to work. I am on Python 2.6.5 with the latest requests library and urllib3.
HTTPS 代理尚未被 urllib3
正确支持(由 requests
使用).
HTTPS proxies are not yet properly supported by urllib3
(used by requests
).
请参阅请求问题 905 和 urllib3 issue 50 了解详情.
Please see requests issue 905 and urllib3 issue 50 for details.