Different results for request() vs putrequest()

John Gordon gordon at panix.com
Fri Sep 11 12:51:05 EDT 2009


In <h7pdan$5iq$1 at reader1.panix.com> John Gordon <gordon at panix.com> writes:

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

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.

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon at panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"




More information about the Python-list mailing list