can't get urllib2 or httplib to work with tor & privoxy
Bob Fnord
bob at example.com
Mon May 9 14:20:01 EDT 2011
Here's my python code:
import httplib, urllib2
proxy_handler = {'http' : 'localhost:8118',
'https' : 'localhost:8118'}
def connect_u2(url = 'http://ipid.shat.net/iponly/'):,
proxied = urllib2.ProxyHandler(proxy_handler)
opnr = urllib2.build_opener(proxied)
opnr.addheaders = [('User-agent', agent)]
rsp = opnr.open(url)
page = rsp.read()
return page
def connect_h(url = 'http://ipid.shat.net/iponly/'):
cnn = httplib.HTTPConnection('127.0.0.1', 8118)
cnn.connect()
cnn.request('GET', url)
rsp = cnn.getresponse()
stderr.write('%u %s\n' % (rsp.status, rsp.reason))
page = rsp.read(500)
cnn.close()
return page
Both methods give me a 503 error, even though this
export http_proxy='http://localhost:8118/'
lynx -dump 'http://ipid.shat.net/iponly/'
works in bash and prints out the IP of a tor exit.
What am I doing wrong in python? (I tried both 'localhost:8118' and
'http://localhost:8118/' in the proxy_handler dict.)
More information about the Python-list
mailing list