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
}
}
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
Bug report
Bug description:
When using the low-level
http.clientAPI, connection timeouts cause theConnectionobject to enter an improper state which seemingly cannot be reset short of creating a newConnectionobject.To reproduce, you'll need an address that produces a timeout. This can be done locally using Python's
http.serverand whichever firewall solution your OS has (since I'm on Linux, this meansnftables):table ip filter { chain input { type filter hook input priority filter; tcp dport 8000 drop } }Finally, in a Python interpreter, do the following:
The following do not fix the state of the
Connection:getresponse(): ReturnsAttributeErrorconnect(): Even if the later connection to the address works, theConnectionremains in an invalid stateCPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs
OSErrorraised byHTTPConnection.getresponse#142339OSErrorraised byHTTPConnection.getresponse(GH-142339) #142704OSErrorraised byHTTPConnection.getresponse(GH-142339) #142705