New submission from Ezio Melotti: urllib.request.Request allows the user to create a request object like: req = Request(url, headers={b'Content-Type': b'application/json'})
When calling urlopen(req, data), urllib will check if a 'Content-Type' header is present and fail to recognize b'Content-Type' because it's bytes. urrlib will therefore add the default Content-Type 'application/x-www-form-urlencoded', and the request will then be sent with both Content-Types. This will result in difficult-to-debug errors because the server will sometimes pick one and sometimes the other, depending on the order. urllib should either reject bytes headers, or check for both bytes and strings. The docs also don't seem to specify that the headers should be strings. ---------- components: Library (Lib) messages: 290063 nosy: ezio.melotti, orsenthil priority: normal severity: normal stage: test needed status: open title: urllib.request.Request accepts but doesn't check bytes headers type: behavior versions: Python 3.5, Python 3.6, Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue29891> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com