Message139512
I came up against a problem today whilst trying to submit a request to a remote API. The header needed to contain:
'Content-MD5' : "md5here"
But the urllib2 Request() forces capitalize() on all header names, and transformed it into "Content-Md5", which in turn made the remote web server ignore the header and break the request (as the remote side is case sensitive, of which we don't have any control over).
I attempted to get smart by using the following patch:
class _str(str):
def capitalize(s):
print s
return s
_headers = {_str("Content-MD5") : 'md5here'}
But this failed to work:
---HEADERS---
{'Content-MD5': 'nts0yj7AdzJALyNOxafDyA=='}
---URLLIB2 DEBUG---
send: 'POST /api/v1 m HTTP/1.1\r\nContent-Md5: nts0yj7AdzJALyNOxafDyA==\r\n\r\n\r\n'
Upon inspecting the urllib2.py source, I found 3 references to capitalize() which seem to cause this problem, but it seems impossible to monkey patch, nor fix without forking.
Therefore, I'd like to +1 a feature request to have an extra option at the time of the request being opened, to bypass the capitalize() on header names (maybe, header_keep_original = True or something).
And, if anyone could suggest a possible monkey patch (which doesn't involve forking huge chunks of code), that'd be good too :)
Thanks
Cal |
|
Date |
User |
Action |
Args |
2011-06-30 19:23:38 | Cal.Leeming | set | recipients:
+ Cal.Leeming |
2011-06-30 19:23:38 | Cal.Leeming | set | messageid: <1309461818.92.0.299415077626.issue12455@psf.upfronthosting.co.za> |
2011-06-30 19:23:38 | Cal.Leeming | link | issue12455 messages |
2011-06-30 19:23:37 | Cal.Leeming | create | |
|