How do I make urllib2 preserve case in HTTP header names?

T

tepples

The HTTP specification, RFC 2616, states that field names in HTTP
headers are case insensitive. But I'm trying to use Python 2.5.1's
urllib2 to interact with a web service offered by Amazon.com, which
deviates from the HTTP spec in that it requires use of case-sensitive
header names ReportName, ReportID, and NumberOfReports. I try to send
an HTTP header named "NumberOfReports", but it comes out mangled as
"Numberofreports'. What is the best way to use Python 2.5.1 on
Windows Server 2003 to create HTTP or HTTPS requests that do not
mangle the case of header field names?

Test case follows:
==========
"""
To see how Python breaks the CaseSensitiveName, go to
command prompt and start netcat listening on the HTTP port:

nc -l -p 80 localhost

Then run this program on the same machine. You will see that
CaseSensitiveName has become Casesensitivename.
"""

import urllib2

req = urllib2.Request("http://localhost/", "")
req.add_header('CaseSensitiveName', 'CaseSensitiveValue')
infp = urllib2.urlopen(req)
data = infp.read()
infp.close()
print data
 
J

John J. Lee

The HTTP specification, RFC 2616, states that field names in HTTP
headers are case insensitive. But I'm trying to use Python 2.5.1's
urllib2 to interact with a web service offered by Amazon.com, which
deviates from the HTTP spec in that it requires use of case-sensitive
header names ReportName, ReportID, and NumberOfReports. I try to send
an HTTP header named "NumberOfReports", but it comes out mangled as
"Numberofreports'. What is the best way to use Python 2.5.1 on
Windows Server 2003 to create HTTP or HTTPS requests that do not
mangle the case of header field names?

httplib


John
 

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,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top