Skip to content

HTTPErrorProcessor uses deprecated members of addinfourl/HTTPResponse #123503

@perey

Description

@perey

code, msg, hdrs = response.code, response.msg, response.info()

Per the docs for urllib.response.addinfourl and http.client.HTTPResponse, response.code and response.info() are deprecated as of Python 3.9. This is an issue when writing handlers that generate their own response objects—these objects must continue to provide the deprecated members.

I admit I don’t know how common or advisable this use case is, but it happened to me while I was implementing HTTP caching. When serving a response from the cache, I didn’t have a “real” response object to modify, and I wasn’t confident that I could instantiate the right thing from the standard library (the docs call it “a http.client.HTTPResponse object slightly modified”).

Instead, I made my own class that implemented just enough of the interface to get by. I thought that headers, status, url, and I/O read operations would suffice… but then I realised that HTTPErrorProcessor runs after all other handlers (including mine). So I would also need to add the deprecated members in order to be compatible.

See also #86203, where (if I’m reading correctly) it’s request objects that need to continue to provide deprecated members in order to work with the standard library.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions