I want to know how i can access a webpage through Tor, in Python.
There are a few similar questions, but none of them are completely answered and alot of the answers outright wrong.
The first page i stumbled upon was this; How to make urllib2 requests through Tor in Python?, and the most popular answer on there is;
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()
there are a few pages with similar answers, anyway somebody on that page commented;
"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."
so this wont get me anywhere, after some searching around i found this Python urllib over TOR?
i downloaded socksipy, and tried the code. it works, but i get the same error as this guy. theres no accepted answer to his problem. the post is from 2011, i thought a new question where i try to clarify was in order.
alternatively, is there a good library for dealing with Tor?
Yup, we have a couple python libraries for working with Tor, the most common ones being stem and txtorcon. For a tutorial on that kind of client usage see here.