This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Usage of HTTPResponse.url
Type: Stage: patch review
Components: Library (Lib) Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: fbidu, martin.panter
Priority: normal Keywords: patch

Created on 2020-10-17 14:13 by fbidu, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 22738 open fbidu, 2020-10-17 14:24
Messages (2)
msg378814 - (view) Author: Felipe Rodrigues (fbidu) * Date: 2020-10-17 14:13
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 `url`
attribute. I tried invoking the `geturl` method and reading the
`HTTPResponse.url` attribute using a sample code from the official docs:

```
import http.client
conn = http.client.HTTPSConnection("www.python.org")
conn.request("GET", "/")
r1 = conn.getresponse()
print(r1.status, r1.reason)

r1.geturl()
r1.url
```
```
import http.client
conn = http.client.HTTPSConnection("www.python.org")
conn.request("GET", "/")
r1 = conn.getresponse()
data1 = r1.read()

conn.request("GET", "/")
r1 = conn.getresponse()
while chunk := r1.read(200):
    print(repr(chunk))
r1.geturl()
r1.url
```

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,
https://github.com/python/cpython/commit/6c5e28c383bf587f80d01e52f887801be200200d 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
msg378846 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2020-10-18 01:59
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 (Issue 12707) the "url" attribute and "geturl" method were documented in the HTTPResponse documentation, which is awkward.
History
Date User Action Args
2022-04-11 14:59:36adminsetgithub: 86228
2020-10-18 01:59:43martin.pantersetnosy: + martin.panter
messages: + msg378846
2020-10-17 14:24:18fbidusetkeywords: + patch
stage: patch review
pull_requests: + pull_request21701
2020-10-17 14:13:56fbiducreate