5

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?!

4
  • Is your Tor node up and running? Do you have the SOCKS proxy activated? Commented Sep 20, 2011 at 22:26
  • Nothings wrong with the code. So, the problem must be in the proxy. Commented Sep 20, 2011 at 22:37
  • Vidalia says I'm connected to Tor and everything is ok. I'm a bit new to proxies. Where can I check if my Socks proxy is activated / get a diagnostics on it? Commented Sep 20, 2011 at 22:55
  • How about your privoxy/polipo status? Commented Dec 19, 2011 at 11:30

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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!

Comments

0

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

1 Comment

Telling someone to google something hardly counts as an answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.