Python Glossary Русский

all Python 3http.clientexception

http.client.UnknownProtocol

exceptions

The server answered with a protocol version http.client does not understand, neither HTTP/1.0 nor HTTP/1.1. A subclass of HTTPException.

Syntax

raise http.client.UnknownProtocol(version)

http.client speaks only HTTP/1.x: a status line of "HTTP/2.0 200 OK" gives UnknownProtocol, and the exception text is the version itself. The module does not support HTTP/2 or HTTP/3 at all; those need third-party clients. A line with no HTTP/ prefix at all is a BadStatusLine instead.

Examples

import http.client
import socket
server, client = socket.socketpair()
server.sendall(b'HTTP/2.0 200 OK\r\n\r\n')
server.close()
resp = http.client.HTTPResponse(client)
try:
    resp.begin()
except http.client.UnknownProtocol as e:
    print('unsupported:', e)  # → unsupported: HTTP/2.0
client.close()

See also

Open in the full glossarydocs.python.orgReport an inaccuracy