[Twisted-web] Proxy Authentication with a Password Protected Site

Robert Hancock hancock.robert at gmail.com
Sun Sep 21 18:13:54 EDT 2008

from twisted.web import client
from twisted.internet import reactor
import base64
import sys

def printPage(data):
    print data

def printError(failure):
    print >> sys.stderr, "Error:", failure.getErrorMessage()

if len(sys.argv) == 4:
    url = sys.argv[1]
    username = sys.argv[2]
    password = sys.argv[3]

    basicAuth = base64.encodestring('%s:%s' % (username, password))
    authHeader = "Basic " + basicAuth.strip()

    client.getPage(url, headers={"Authorization":
    print 'Usage: get_web_page.py <URL>'

If I run this against a password protected HTTP(S) site from a host
that has direct access to the Internet it works fine.  I now have to
move it behind a proxy that requires authentication.  The Twisted
documentation did not make it clear (to me) how to add proxy
authentication and I cannot find an example on the Internet.

I've tried adding an additional Proxy-Authentication header to the
call, but that doesn't help  Any ideas would be greatly appreciated.

More information about the Twisted-web mailing list