Python Glossary Русский

all Python 3http.clientexception

http.client.NotConnected

exceptions

An attempt to send data over a connection that has no socket while automatic connecting is off (auto_open = 0). A subclass of HTTPException.

Syntax

raise http.client.NotConnected()

It rarely shows up in normal code: by default send() and request() call connect() themselves when there is no socket. You see it when auto_open is turned off (wrappers that manage the socket themselves do that) or after close() in that mode. Network errors while connecting are OSError, not NotConnected.

Examples

import http.client
conn = http.client.HTTPConnection('example.com')
conn.auto_open = 0  # не подключаться самому
try:
    conn.send(b'GET / HTTP/1.1\r\n\r\n')
except http.client.NotConnected as e:
    print(type(e).__name__, repr(e))  # → NotConnected NotConnected()

See also

Open in the full glossarydocs.python.orgReport an inaccuracy