Title: Usage of HTTPResponse.url
Type: Stage: patch review
Components: Library (Lib) Versions:
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 2020-10-18 01:59 by martin.panter.

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/, 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("")
conn.request("GET", "/")
r1 = conn.getresponse()
print(r1.status, r1.reason)

import http.client
conn = http.client.HTTPSConnection("")
conn.request("GET", "/")
r1 = conn.getresponse()
data1 =

conn.request("GET", "/")
r1 = conn.getresponse()
while chunk :=

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, 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.
Date User Action Args
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