Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #5003

can't get urllib2 or httplib to work with tor & privoxy

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 <abuse@frell.theremailer.net>. 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 <bob@example.com>
Message-ID <d5e2985d74a2117de3fd9ab09c99b799@msgid.frell.theremailer.net> (permalink)
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

Show key headers only | View raw


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.)

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

can't get urllib2 or httplib to work with tor & privoxy Bob Fnord <bob@example.com> - 2011-05-09 20:20 +0200
  Re: can't get urllib2 or httplib to work with tor & privoxy Chris Angelico <rosuav@gmail.com> - 2011-05-10 20:33 +1000
    Re: can't get urllib2 or httplib to work with tor & privoxy Bob Fnord <bob@example.com> - 2011-05-12 17:51 +0200

csiph-web