text ) # The text will either be decoded with the Content-Type # charset, or using "shift-jis". encoding ) # This will either print the charset given in # the Content-Type charset, or else "shift-jis". Client ( default_encoding = "shift-jis" ) # Using the client. Import httpx # Instantiate a client with a Japanese character set as the default encoding. This will ensure that connections are properly cleaned up when leaving the with block: The recommended way to use a Client is as a context manager. ![]() The other sections on this page go into further detail about what you can do with a Client instance. Applying configuration across all outgoing requests.Reduced latency across requests (no handshaking).Ĭlient instances also support features that aren't available at the top-level API, such as:.This can bring significant performance improvements compared to using the top-level API, including: This means that when you make several requests to the same host, the Client will reuse the underlying TCP connection, instead of recreating one for every single request. ![]() On the other hand, a Client instance uses HTTP connection pooling. As the number of requests to a host increases, this quickly becomes inefficient. When you make requests using the top-level API as documented in the Quickstart guide, HTTPX has to establish a new connection for every single request (connections are not reused). ![]() More efficient usage of network resources If you do anything more than experimentation, one-off scripts, or prototypes, then you should use a Client instance. More efficient usage of network resourcesĬharacter set encodings and auto-detection
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |