1

I am looking how to bypass pass proxy using tor and torctl, I looked on various steps and wrote this script in python.

After starting tor, ideally this should work

proxy_support = urllib2.ProxyHandler({"http" : "127.0.0.1:8118"} )
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
#urllib2.urlopen('http://www.google.fr')
data = json.load(urllib2.urlopen("https://www.google.co.in/trends/hottrends/hotItems?geo=IN&mob=0&hvsm=0"))

which again gives this message :

File "/usr/lib/python2.7/urllib2.py", line 528, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 503: Service Unavailable

I have already started tor and enabled control port using

tor --controlport 9051

Do I need to make any other change?

EDIT treaceback after change as per new answer of running tor on 1080 port

>>> import urllib2
>>> proxy_support = urllib2.ProxyHandler({"http" : "127.0.0.1:1080"})
>>> opener = urllib2.build_opener(proxy_support)
>>> urllib2.install_opener(opener)
>>> import json 
>>> data = json.load(urllib2.urlopen("https://www.google.co.in/trends/hottrends/hotItems?geo=IN&mob=0&hvsm=0"))
('216.58.220.3', 443)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 407, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 520, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 445, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 379, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 528, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 503: Service Unavailable
user123
  • 5,269
  • 16
  • 73
  • 121

1 Answers1

1

You can use tor as a SOCKS proxy.

Start tor with:

tor SOCKSPort 1080

And use the SOCKS 5 proxy at 127.0.0.1:1080.

Also check this question on how to use a SOCKS proxy with urllib2.

Community
  • 1
  • 1
fferri
  • 18,285
  • 5
  • 46
  • 95
  • that's because Google is not serving requests generated from tor exit nodes. I get that error too, but do not get that error when connecting to other servers. – fferri Jun 04 '15 at 13:22
  • unfortunately exit nodes direct a lot of traffic towards Google, and Google sees that as a potential abuse of its services, and tries to block those (automatically generated) requests. you may have better luck by changing exit node – fferri Jun 04 '15 at 13:29
  • any light on exite node? – user123 Jun 04 '15 at 13:37
  • it changes every time you connect to tor, but you might get a better answer about this on http://tor.stackexchange.com/. see also http://tor.stackexchange.com/questions/733/can-i-exit-from-a-specific-country-or-node – fferri Jun 04 '15 at 13:39