all Python 3http.clientexception
http.client.CannotSendRequest
exceptions
A new request was started while the connection is still busy with the previous one: that request is unfinished or its response unread. A subclass of ImproperConnectionState.
Syntax
except http.client.CannotSendRequest as e: ...
The typical scenario: two request() calls in a row without getresponse() and read() in between, or one HTTPConnection shared by several threads. The cure is to read every response or to open one connection per thread. The exception text is the state the connection was in: 'Request-started' or 'Request-sent'.
Examples
import http.client
conn = http.client.HTTPConnection('example.com')
conn.putrequest('GET', '/a') # сети ещё не нужно
try:
conn.putrequest('GET', '/b')
except http.client.CannotSendRequest as e:
print(repr(e)) # → CannotSendRequest('Request-started')
See also
Open in the full glossarydocs.python.orgReport an inaccuracy