You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
assignee=Noneclosed_at=Nonecreated_at=<Date2020-10-17.14:13:56.336>labels= ['library']
title='Usage of HTTPResponse.url'updated_at=<Date2020-10-18.01:59:43.626>user='https://github.com/fbidu'
While testing some static analysis tools on HTTP/client.py, Pylint pointed
me to HTTPResponse.geturl() method with a "no-member" error for the url
attribute. I tried invoking the geturl method and reading the HTTPResponse.url attribute using a sample code from the official docs:
Both of those examples will raise an AttributeError: 'HTTPResponse' object has no attribute 'url'.
I tried searching through this module's history from when this line originally appeared, 6c5e28c but
I wasn't able to find this attribute being set internally by the class, even
though there is an url attribute at init.
So, I wonder if this attribute was intended to be set externally as in r1.url = 'something'
or if it is just a bug
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.
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'
Activity
fbidu commentedon Oct 17, 2020
Hello all,
While testing some static analysis tools on HTTP/client.py, Pylint pointed
me to HTTPResponse.geturl() method with a "no-member" error for the
urlattribute. I tried invoking the
geturlmethod and reading theHTTPResponse.urlattribute using a sample code from the official docs:Both of those examples will raise an
AttributeError: 'HTTPResponse' object has no attribute 'url'.I tried searching through this module's history from when this line originally appeared,
6c5e28c but
I wasn't able to find this attribute being set internally by the class, even
though there is an
urlattribute at init.So, I wonder if this attribute was intended to be set externally as in
r1.url = 'something'or if it is just a bug
vadmium commentedon Oct 18, 2020
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.
dimo414 commentedon Jan 9, 2024
This seems to still be broken in 3.12:
HTTPResponse.urldoesn't exist, andHTTPResponse.geturl()is broken. I tried 3.12, 3.11, 3.10, 3.9, and 3.8 (prior to #11447), it doesn't look like this has ever worked.FYI @merwok and @matrixise who approved #11447.
merwok commentedon Jan 9, 2024
Tangent: I now wish the original PR had also updated the docstrings on the deprecated methods (it only added a code comment).
vadmium commentedon Feb 6, 2024
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:
[fix] AttributeError: 'HTTPResponse' object has no attribute 'url'
futurend commentedon May 26, 2025
Still present on Python 3.13.3 in 26 may 2025
pythongh-86228: Initialize HTTPResponse.url in __init__ (bpo-42062)
pythongh-86228: Initialize HTTPResponse.url in __init__ (bpo-42062)