Pycurl proxy authentication anyone?

Discussion in 'Python' started by Mark Ferguson, Nov 5, 2003.

  1. 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.StringIO()
    c = Curl()

    c.setopt(URL, "http://www.google.com/")
    c.setopt(VERBOSE,1)
    c.setopt(HTTPHEADER, ["User-Agent: Mozilla/5.001 (windows; U; NT4.0;
    en-us) Gecko/25250101", "Agent: "])
    c.setopt(PROXY, "dummyproxy")
    c.setopt(PROXYPORT,80)
    c.setopt(PROXYUSERPWD,"dummyuser:dummypasswd")
    c.setopt(HTTPAUTH,8) #NTLM
    c.setopt(WRITEFUNCTION, b.write)
    c.setopt(FOLLOWLOCATION, 1)
    c.setopt(MAXREDIRS, 5)

    c.perform()
    print b.getvalue()

    And I get....

    * About to connect() to dummyproxy:80
    * Connected to dummyproxy (10.10.10.10) port 80
    > GET http://www.google.com/ HTTP/1.1

    Proxy-authorization: Basic ZHVtbXl1c2VyOmR1bW15cGFzc3dk
    Authorization: NTLM TlRMTVNTUAABAAAAAgIAAAAAAAAgAAAAAAAAACAAAAA=
    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><title>Error 407</title>

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

    <body>

    <h2>HTTP Error 407</h2>

    <p><strong>407 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:password combo are correct.

    I'm stumped! suggestions gratefully accepted..

    Mark.
    Mark Ferguson, Nov 5, 2003
    #1
    1. Advertising

  2. Mark Ferguson

    JanC Guest

    Mark Ferguson <> schreef:

    > 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!):


    > c.setopt(PROXYPORT,80)
    > c.setopt(PROXYUSERPWD,"dummyuser:dummypasswd")
    > c.setopt(HTTPAUTH,8) #NTLM


    Shouldn't that last line be:

    c.setopt(PROXYAUTH,8) #NTLM

    --
    JanC

    "Be strict when sending and tolerant when receiving."
    RFC 1958 - Architectural Principles of the Internet - section 3.9
    JanC, Nov 7, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jesse Noller

    Read a binary file and feed it to PyCURL

    Jesse Noller, Feb 4, 2004, in forum: Python
    Replies:
    0
    Views:
    440
    Jesse Noller
    Feb 4, 2004
  2. Michele Simionato

    users of pycurl here?

    Michele Simionato, Oct 7, 2005, in forum: Python
    Replies:
    4
    Views:
    296
    Michele Simionato
    Oct 10, 2005
  3. Replies:
    0
    Views:
    463
  4. Ju Hui
    Replies:
    1
    Views:
    875
    Josef Meile
    Apr 13, 2006
  5. Ju Hui
    Replies:
    4
    Views:
    4,194
    John J. Lee
    Apr 21, 2006
Loading...

Share This Page