Skip to content

urllib.request.urlopen() no longer respects the http.client.HTTPConnection.debuglevel flag #99352

Closed
@wheelerlaw

Description

@wheelerlaw

Bug report

The urllib.request.urlopen() function used to respect the debug flag set in http.client.HTTPConnection.debuglevel prior to Python 3.5.2. For example:

wheeler@fedora:~/cpython$ docker run -it --rm docker.io/library/fedora:24 /bin/bash
[root@253ea28b060c /]# python3
Python 3.5.1 (default, Mar  4 2016, 15:21:15) 
[GCC 6.0.0 20160302 (Red Hat 6.0.0-0.14)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import http.client
>>> import urllib.request
>>> http.client.HTTPConnection.debuglevel=1
>>> urllib.request.urlopen("http://example.com")
send: b'GET / HTTP/1.1\r\nAccept-Encoding: identity\r\nConnection: close\r\nHost: example.com\r\nUser-Agent: Python-urllib/3.5\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Age header: Cache-Control header: Content-Type header: Date header: Etag header: Expires header: Last-Modified header: Server header: Vary header: X-Cache header: Content-Length header: Connection <http.client.HTTPResponse object at 0x7faa82fe2940>
>>>   

When this change was introduced to respect the debuglevel argument in the constructor for urllib.request.AbstractHTTPHandler and urllib.request.HTTPSHandler, this caused the global HTTPConnection.debuglevel to be ignored, even when a value is not passed to AbstractHTTPHandler's and HTTPSHandler's constructor:

wheeler@fedora:~/cpython$ docker run -it --rm docker.io/library/fedora:25 /bin/bash
[root@65781375bc01 /]# python3
Python 3.5.4 (default, Aug 23 2017, 18:32:05) 
[GCC 6.4.1 20170727 (Red Hat 6.4.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import http.client
>>> import urllib.request
>>> http.client.HTTPConnection.debuglevel=1
>>> urllib.request.urlopen("http://example.com")
<http.client.HTTPResponse object at 0x7f73690a7048>
>>> 

Your environment

  • CPython versions tested on:
    • 3.5.1 (working)
    • 3.5.4 (not working)
    • 3.10.7 (not working)
  • Operating system and architecture:
    • Fedora 24 (working)
    • Fedora 25 (not working)
    • Fedora 36 (not working)

I tested it out in two Docker containers to verify that there was a point at which it worked. I also tested it out on the system interpreter on my local machine to verify that it was still not working on a more recent version of Python. I checked the contents of the request.py in the stdlib on my machine and compared it with the contents in the trunk branch of this repo and I saw that the functionality was essentially the same.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions