[英]Python fails Tor check using urllib2 to initiate requests
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: 在阅读了StackOverflow上的其他 问题后 ,我得到了一段Python代码,可以通过Tor代理发出请求:
import urllib2
proxy = urllib2.ProxyHandler({'http':'127.0.0.1:8118'})
opener = urllib2.build_opener(proxy)
print opener.open('https://check.torproject.org/').read()
Since Tor works fine in Firefox with TorButton, I expected it to work fine in Python. 由于Tor使用TorButton在Firefox中运行良好,我希望它能在Python中正常工作。 Unfortunately, included in the mess of HTML:
Sorry. You are not using Tor
不幸的是,包含在乱七八糟的HTML中:
Sorry. You are not using Tor
Sorry. You are not using Tor
. Sorry. You are not using Tor
。 I am not sure why this is the case or how to get Tor working properly with urllib2
. 我不确定为什么会这样,或者如何让ur使用
urllib2
正常工作。
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". 您已为
http
协议设置了本地Tor实例的代理,但您使用https
与“check.torproject.org”进行通信。 Try: 尝试:
print opener.open('http://check.torproject.org/').read()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.