Twisted: Get Protected HTTPS Page via Proxy with Authentication

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert Hancock

    Twisted: Get Protected HTTPS Page via Proxy with Authentication

    from twisted.web import client
    from twisted.interne t import reactor
    import base64
    import sys

    def printPage(data) :
    print data
    reactor.stop()

    def printError(fail ure):
    print >sys.stderr, "Error:", failure.getErro rMessage()
    reactor.stop()

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

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

    client.getPage( url, headers={"Autho rization":
    authHeader}).ad dCallback(print Page).addErrbac k(printError)
    reactor.run()
    else:
    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.

    Command line args: http://feedparser.org/docs/examples/basic_auth.xml
    test basic
  • Robert Hancock

    #2
    Re: Twisted: Get Protected HTTPS Page via Proxy with Authentication

    This works:
    # Proxy credentials
    proxyAuth = base64.encodest ring('%s:%s' % (proxy_username ,
    proxy_password) )
    proxy_authHeade r = "Basic " + proxyAuth.strip ()

    # Web site credentials
    basicAuth = base64.encodest ring('%s:%s' % (username,
    password))
    authHeader = "Basic " + basicAuth.strip ()

    return client.getPage( url, headers={"Autho rization":
    authHeader, 'Proxy-Authenticate': proxy_authHeade r})

    Comment

    Working...