python / python/cpython

`HTTPErrorProcessor` uses deprecated members of `addinfourl`/`HTTPResponse`

Open
#123,503 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

https://github.com/python/cpython/blob/0181aa2e3efedc6504b27f6fe74f096e5e454286/Lib/urllib/request.py#L625

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
  • gh-123509
  • gh-123541
  • gh-132644
  • gh-132670

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read Lib/urllib/request.py at the HTTPErrorProcessor implementation linked in the issue, focusing on its use of response.code and response.info(). Check the linked PRs before starting, then confirm that generated response objects no longer need those deprecated members while preserving the handler's behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.