Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wheelerlaw opened this issue Nov 10, 2022 · 0 comments · Fixed by #99353
Closed
Labels
type-bug An unexpected behavior, bug, or error

Comments

@wheelerlaw
Copy link
Contributor

wheelerlaw commented Nov 10, 2022

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.

@wheelerlaw wheelerlaw added the type-bug An unexpected behavior, bug, or error label Nov 10, 2022
orsenthil added a commit that referenced this issue Apr 21, 2023
…request.AbstractHTTPHandler` (#99353)

* bugfix: let the HTTP- and HTTPSHandlers respect the value of http.client.HTTPConnection.debuglevel

* add tests

* add news

* ReSTify NEWS and reword a bit.

* Address Review Comments.

* Use mock.patch.object instead of settting the module level value.
* Used test values to assert the debuglevel.

---------

Co-authored-by: Gregory P. Smith <[email protected]>
Co-authored-by: Senthil Kumaran <[email protected]>
orsenthil added a commit that referenced this issue Apr 26, 2023
…s tests. (#103828)

gh-99352: Ensure HTTPSConnection is available before exercising https
tests.

This will fix the buildbot issue mentioned in

#99353
itamaro pushed a commit to itamaro/cpython that referenced this issue Apr 26, 2023
…g https tests. (python#103828)

pythongh-99352: Ensure HTTPSConnection is available before exercising https
tests.

This will fix the buildbot issue mentioned in

python#99353
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
1 participant