New submission from Terry J. Reedy:

Code based on python-list post by a do-not-wish-to-register urllib user.

import urllib.request
opener = urllib.request.build_opener()
request = urllib.request.Request("http://example.com/";, headers =
        {"Content-Type": "application/x-www-form-urlencoded"})
print(request.data, '\n', request.header_items())

opener.open(request, "1".encode("us-ascii"))
print(request.data, '\n', request.header_items())

opener.open(request, "123456789".encode("us-ascii"))
print(request.data, '\n', request.header_items())
>>> 
None 
 [('Content-type', 'application/x-www-form-urlencoded')]
b'1' 
 [('Content-length', '1'), ('Host', 'example.com'), ('User-agent', 
'Python-urllib/3.3'), ('Content-type', 'application/x-www-form-urlencoded')]
b'123456789' 
 [('Content-length', '1'), ('Host', 'example.com'), ('User-agent', 
'Python-urllib/3.3'), ('Content-type', 'application/x-www-form-urlencoded')]

The first opener.open adds data and several headers to request, including 
content-length. The second changes the data but not the content-length. The 
docs do not say anything about this either way.

----------
messages: 175485
nosy: orsenthil, terry.reedy
priority: normal
severity: normal
stage: needs patch
status: open
title: urllib.request: opener not resetting content-length
type: behavior
versions: Python 3.3

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue16464>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to