-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Usage of HTTPResponse.url #86228
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
Comments
Hello all, While testing some static analysis tools on HTTP/client.py, Pylint pointed
Both of those examples will raise an I tried searching through this module's history from when this line originally appeared, So, I wonder if this attribute was intended to be set externally as in |
There is a comment in the HTTPResponse class regarding these methods: # For compatibility with old-style urllib responses. They were there for the "urlopen" API in "urllib.request", not for the "http.client" module on its own. I expect the "url" attribute is set by the "urlopen" code. However more recently (bpo-12707) the "url" attribute and "geturl" method were documented in the HTTPResponse documentation, which is awkward. |
This seems to still be broken in 3.12:
FYI @merwok and @matrixise who approved #11447. |
Tangent: I now wish the original PR had also updated the docstrings on the deprecated methods (it only added a code comment). |
Another problem with this documentation is it suggests HTTPResponse.headers is an EmailMessage instance, while HTTPResponse.msg remains only a (subclassed) instance of email.message.Message. And addinfourl.info and addinfourl.headers are now supposed to return an EmailMessage, although .info was previously (indirectly) documented to return an email.message.Message. I tested Python 3.10.2 and it seems HTTPResponse.headers has not changed because the object didn’t have one of the methods unique to EmailMessage: >>> u = urlopen('http://google.com')
>>> u.headers.is_attachment
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'HTTPMessage' object has no attribute 'is_attachment' |
Though not directly relevant, this is also an issue with cpython: python/cpython#86228 and there is an open pull request: https://github.com/python/cpython/pull/22738/files Pyodide uses Javascript XHR to perform the network request, and constructs an 'HTTPResponse' object from the XHR response. When doing so, a 'url' attribute should be added.
Still present on Python 3.13.3 in 26 may 2025 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: