Pycurl proxy authentication anyone?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Ferguson

    Pycurl proxy authentication anyone?

    I've been trying to get a simple pycurl script working with an
    authenticating proxy, here is the code (with changes to protect the
    guilty!):

    from pycurl import *
    import StringIO

    b = StringIO.String IO()
    c = Curl()

    c.setopt(URL, "http://www.google.com/")
    c.setopt(VERBOS E,1)
    c.setopt(HTTPHE ADER, ["User-Agent: Mozilla/5.001 (windows; U; NT4.0;
    en-us) Gecko/25250101", "Agent: "])
    c.setopt(PROXY, "dummyproxy ")
    c.setopt(PROXYP ORT,80)
    c.setopt(PROXYU SERPWD,"dummyus er:dummypasswd" )
    c.setopt(HTTPAU TH,8) #NTLM
    c.setopt(WRITEF UNCTION, b.write)
    c.setopt(FOLLOW LOCATION, 1)
    c.setopt(MAXRED IRS, 5)

    c.perform()
    print b.getvalue()

    And I get....

    * About to connect() to dummyproxy:80
    * Connected to dummyproxy (10.10.10.10) port 80[color=blue]
    > GET http://www.google.com/ HTTP/1.1[/color]
    Proxy-authorization: Basic ZHVtbXl1c2VyOmR 1bW15cGFzc3dk
    Authorization: NTLM TlRMTVNTUAABAAA AAgIAAAAAAAAgAA AAAAAAACAAAAA=
    Host: www.google.com
    Pragma: no-cache
    Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
    User-Agent: Mozilla/5.001 (windows; U; NT4.0; en-us) Gecko/25250101

    < HTTP/1.1 407 Proxy authentication required
    < Proxy-Authenticate: NTLM
    < Proxy-Connection: close
    < Content-Length: 503
    < Content-Type: text/html
    * Connection #0 left intact
    <html><head><ti tle>Error 407</title>

    <meta name="robots" content="noinde x">
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html;
    charset=iso-8859-1"></head>

    <body>

    <h2>HTTP Error 407</h2>

    <p><strong>40 7 Proxy Authentication Required</strong></p>

    <p>You must authenticate with a proxy server before this request can be
    service
    nd then try again.</p>

    <p>Please contact the Web server's administrator if this problem
    persists.</p>

    </body></html>
    * Closing connection #0

    The username:passwo rd combo are correct.

    I'm stumped! suggestions gratefully accepted..

    Mark.



  • JanC

    #2
    Re: Pycurl proxy authentication anyone?

    Mark Ferguson <mark.ferguson@ newellandbudge. com> schreef:
    [color=blue]
    > I've been trying to get a simple pycurl script working with an
    > authenticating proxy, here is the code (with changes to protect the
    > guilty!):[/color]
    [color=blue]
    > c.setopt(PROXYP ORT,80)
    > c.setopt(PROXYU SERPWD,"dummyus er:dummypasswd" )
    > c.setopt(HTTPAU TH,8) #NTLM[/color]

    Shouldn't that last line be:

    c.setopt(PROXYA UTH,8) #NTLM

    --
    JanC

    "Be strict when sending and tolerant when receiving."
    RFC 1958 - Architectural Principles of the Internet - section 3.9

    Comment

    Working...