Path: csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!usenet.pasdenom.info!news.albasani.net!news2.arglkargh.de!news.theremailer.net!frell.theremailer.net!anonymous Comments: This message did not originate from the Sender address above. It was remailed automatically by anonymizing remailer software. Please report problems or inappropriate use to the remailer administrator at . Identifying the real sender is technically impossible. Newsgroups: comp.lang.python Subject: can't get urllib2 or httplib to work with tor & privoxy From: Bob Fnord Message-ID: Precedence: anon Date: Mon, 09 May 2011 20:20:01 +0200 Mail-To-News-Contact: abuse@frell.theremailer.net Organization: Frell Anonymous Remailer Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5003 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.)