Trying to get Tor to work with Python, but keep getting connection refused.?

匿名 (未验证) 提交于 2019-12-03 03:10:03

问题:

I've been trying to get Tor to work with Python, but I've been hitting a brick wall. I simply can't get any of the examples to work. Here is one from Stackoverflow

import urllib2 proxy  = urllib2.ProxyHandler({'http':'127.0.0.1:8118'}) opener = urllib2.build_opener(proxy) print opener.open('http://check.torproject.org/').read() 

I've installed Tor and it works fine while browsing through Aurora. However running this python script I get

Traceback (most recent call last): File "/home/x/Tor.py", line 4, in <module>   print opener.open('http://check.torproject.org/').read() File "/usr/lib/python2.6/urllib2.py", line 391, in open   response = self._open(req, data) File "/usr/lib/python2.6/urllib2.py", line 409, in _open   '_open', req) File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain   result = func(*args) File "/usr/lib/python2.6/urllib2.py", line 1161, in http_open   return self.do_open(httplib.HTTPConnection, req) File "/usr/lib/python2.6/urllib2.py", line 1136, in do_open   raise URLError(err) urllib2.URLError: <urlopen error [Errno 111] Connection refused> 

I've searched the web, but been unable to find people with simiair problems. Am I missing something totally obvious?!

回答1:

I've written an article showing how to use Tor with Python (using SOCKS) on http://blog.databigbang.com/distributed-scraping-with-multiple-tor-circuits/

Hope it helps.



回答2:

I have the same problem but can not find a solution!

I am running Ubuntu, I can open TOR (latest version) with Vidalia, and surf the web correctly. So vidalia works and is connected.

If I use TorCtl in python, I get a response from TOR saying it is live and running!

However, if I want to open a page using urllib2 as described by Loko, I get the same answer.

If someone has a good idea, it would be really nice!



回答3:

Tor acts as a Socks5 proxy. You need to configure your script with that in mind. Google "socks.py"



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!