[New-bugs-announce] [issue33365] http/client.py does not print correct headers in debug

Marco Strigl report at bugs.python.org
Thu Apr 26 08:12:56 EDT 2018


New submission from Marco Strigl <marco.strigl at googlemail.com>:

Consider the following script: 

try:
    from urllib import request
except ImportError:
    import urllib2 as request

handler = request.HTTPSHandler(debuglevel=1)
opener = request.build_opener(handler)
f = opener.open('https://httpbin.org/user-agent')


In python2.x this works: 

$ python2 http_client_bug.py
send: 'GET /user-agent HTTP/1.1\r\nAccept-Encoding: identity\r\nHost:
httpbin.org\r\nConnection: close\r\nUser-Agent: Python-urllib/2.7\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Connection: close
header: Server: gunicorn/19.7.1
header: Date: Thu, 26 Apr 2018 12:01:35 GMT
header: Content-Type: application/json
header: Access-Control-Allow-Origin: *
header: Access-Control-Allow-Credentials: true
header: X-Powered-By: Flask
header: X-Processed-Time: 0
header: Content-Length: 40
header: Via: 1.1 vegur


But in python3.x only the header keys are printed. Not the values (also a newline after each header will be nice):

$ python3 http_client_bug.py
send: b'GET /user-agent HTTP/1.1\r\nAccept-Encoding: identity\r\nHost:
httpbin.org\r\nUser-Agent: Python-urllib/3.6\r\nConnection: close\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Connection header: Server header: Date header: Content-Type
header: Access-Control-Allow-Origin header:
Access-Control-Allow-Credentials header: X-Powered-By header:
X-Processed-Time header: Content-Length header:

Patch for this is attached.

----------
components: Library (Lib)
files: complete_pretty_headers.patch
keywords: patch
messages: 315787
nosy: mstrigl
priority: normal
severity: normal
status: open
title: http/client.py does not print correct headers in debug
versions: Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8
Added file: https://bugs.python.org/file47550/complete_pretty_headers.patch

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33365>
_______________________________________


More information about the New-bugs-announce mailing list