Different results for request() vs putrequest()

J

John Gordon

According to the documentation, these two sections of code should be
equivalent:

conn = httplib.HTTPSConnection(host)
conn.putrequest("POST", url)
conn.putheader("Proxy-Authorization", myProxy)
conn.putheader("Content-Length", "%d" % len(body))
conn.endheaders()
conn.send(body)

vs

headers = { "Proxy-Authorization": myProxy }
conn = httplib.HTTPSConnection(host)
conn.request("POST", url, body, headers)

And yet they are not. The first section works, but I get an
"HTTP/1.1 401 Unauthorized" error from the second.

Anyone know why?
 
J

John Gordon

In said:
According to the documentation, these two sections of code should be
equivalent:
conn = httplib.HTTPSConnection(host)
conn.putrequest("POST", url)
conn.putheader("Proxy-Authorization", myProxy)
conn.putheader("Content-Length", "%d" % len(body))
conn.endheaders()
conn.send(body)

headers = { "Proxy-Authorization": myProxy }
conn = httplib.HTTPSConnection(host)
conn.request("POST", url, body, headers)
And yet they are not. The first section works, but I get an
"HTTP/1.1 401 Unauthorized" error from the second.

To follow up my own post, this was happening because of a trailing
newline in myProxy, put there by base64.encodestring().

The newline made the server stop processing any subsequent headers.
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top