Pycurl proxy authentication anyone?

M

Mark Ferguson

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

JanC

Mark Ferguson said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top