Skip to content

Improve documentation about treatment of OSError raised by HTTPConnection.getresponse #141938

@7cff

Description

@7cff

Bug report

Bug description:

When using the low-level http.client API, connection timeouts cause the Connection object to enter an improper state which seemingly cannot be reset short of creating a new Connection object.

To reproduce, you'll need an address that produces a timeout. This can be done locally using Python's http.server and whichever firewall solution your OS has (since I'm on Linux, this means nftables):

table ip filter {
	chain input {
		type filter hook input priority filter;
		tcp dport 8000 drop
	}
}
python -m http.server

Finally, in a Python interpreter, do the following:

from http.client import HTTPConnection
conn = HTTPConnection('127.0.0.1', 8000)
# this request throws TimeoutError
conn.request('HEAD', '/')
# this request throws CannotSendRequest
conn.request('HEAD', '/')

The following do not fix the state of the Connection:

  • getresponse(): Returns AttributeError
  • connect(): Even if the later connection to the address works, the Connection remains in an invalid state

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions