Python 使用 urllib2 发起请求的 Tor 检查失败 [英] Python fails Tor check using urllib2 to initiate requests
问题描述
阅读其他后问题 在 StackOverflow 上,我得到了一段 Python 代码,可以通过 Tor 代理发出请求:
After reading through the other questions on StackOverflow, I got a snippet of Python code that is able to make requests through a Tor proxy:
import urllib2
proxy = urllib2.ProxyHandler({'http':'127.0.0.1:8118'})
opener = urllib2.build_opener(proxy)
print opener.open('https://check.torproject.org/').read()
由于 Tor 在带有 TorButton 的 Firefox 中运行良好,我希望它在 Python 中运行良好.不幸的是,包含在乱七八糟的 HTML 中:Sorry.您没有使用 Tor
.我不确定为什么会这样,或者如何让 Tor 与 urllib2
一起正常工作.
Since Tor works fine in Firefox with TorButton, I expected it to work fine in Python. Unfortunately, included in the mess of HTML: Sorry. You are not using Tor
. I am not sure why this is the case or how to get Tor working properly with urllib2
.
推荐答案
您已经为 http
协议设置了本地 Tor 实例的代理,但您使用的是 https
与check.torproject.org"交谈.试试:
You've set up a proxy to your local Tor instance for the http
protocol, but you're using https
to talk to "check.torproject.org". Try:
print opener.open('http://check.torproject.org/').read()
这篇关于Python 使用 urllib2 发起请求的 Tor 检查失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!