[issue7540] urllib2 request does not update content length after new add_data

Pablo Mouzo report at bugs.python.org
Sun Dec 27 18:18:20 CET 2009


Pablo Mouzo <pablomouzo at gmail.com> added the comment:

The problem here is that the headers are not updated if they already 
exists. The solution is quite simple but breaks the tests because it 
"clobbers the existing headers".

You can do this:
...
req.add_data(some_data)
req.add_unredirected_header('Content-Length', len(some_data))
urllib2.urlopen(req)
...

But is risky because all the other headers are still outdated.

Is there any reason why you need to reuse the request object?

----------
keywords: +patch
nosy: +pablomouzo
Added file: http://bugs.python.org/file15680/bad_fix.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7540>
_______________________________________


More information about the Python-bugs-list mailing list