linux tor python,与TOR运行Python脚本

你好!起初我想确保有类似的话题,但没有公认的答案或明确的回应。所以我想结合他们再问一次。我有以下脚本:与TOR运行Python脚本

import urllib2

proxy = urllib2.ProxyHandler({"http":"127.0.0.1:9050"})

opener = urllib2.build_opener(proxy)

print(opener.open("http://www.ifconfig.me/ip").read())

我想运行它匿名,使用与tor例如。但它给这个错误:

Traceback (most recent call last):

File "python_tor.py", line 5, in

print(opener.open("http://www.ifconfig.me/ip").read())

File "/usr/lib/python2.7/urllib2.py", line 400, in open

response = meth(req, response)

File "/usr/lib/python2.7/urllib2.py", line 513, in http_response

'http', request, response, code, msg, hdrs)

File "/usr/lib/python2.7/urllib2.py", line 438, in error

return self._call_chain(*args)

File "/usr/lib/python2.7/urllib2.py", line 372, in _call_chain

result = func(*args)

File "/usr/lib/python2.7/urllib2.py", line 521, in http_error_default

raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)

urllib2.HTTPError: HTTP Error 501: Tor is not an HTTP Proxy

我发现下面的计算器答案:

proxy_support = urllib2.ProxyHandler({"http" : "127.0.0.1:8118"})

opener = urllib2.build_opener(proxy_support)

opener.addheaders = [('User-agent', 'Mozilla/5.0')]

print opener.open('http://www.google.com').read()

,同时也为这个话题到此评论:

It may be worthwhile for people reading this thread to know that port 8118 is actually Privoxy's port, not Tor. Tor is a strictly SOCKS-only proxy (port 9050) so it rejects all non-SOCKS traffic (e.g. HTTP). To handle non-SOCKS traffic, you would need to use Privoxy (port 8118) or Polipo (port 8123) to translate the traffic into SOCKS so Tor would accept.

Privoxy is better for privacy and Polipo is better for performance because it does caching.

任何人都可以解释如何执行我脚本匿名?

+0

[Tor with Python?](http://stackoverflow.com/questions/1096379/tor-with-python) –

2012-03-26 10:07:37

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值