Python Glossary Русский

all Python 3http.clientexception

http.client.UnknownTransferEncoding

exceptions

An exception for an unknown Transfer-Encoding. It is kept for compatibility: modern http.client never raises it. A subclass of HTTPException.

Syntax

except http.client.UnknownTransferEncoding: ...

Catching it is pointless: if the server sends, say, Transfer-Encoding: gzip, the module does not fail; it treats the body as not chunked and reads it as is, up to Content-Length or connection close. Decompressing gzip is up to you (the gzip or zlib module). The class stays in the module so that old code with except UnknownTransferEncoding does not break on import.

Examples

import http.client
import socket
server, client = socket.socketpair()
server.sendall(b'HTTP/1.1 200 OK\r\nTransfer-Encoding: gzip\r\n\r\nraw')
server.close()
resp = http.client.HTTPResponse(client)
resp.begin()  # никакого UnknownTransferEncoding
print(resp.read())  # → b'raw' — тело как есть, до закрытия соединения
print(issubclass(http.client.UnknownTransferEncoding, http.client.HTTPException))  # → True
client.close()

See also

Open in the full glossarydocs.python.orgReport an inaccuracy