@@ -56,7 +56,7 @@ finally:
5656
5757Once you have a ` Client ` , you can send requests using ` .get() ` , ` .post() ` , etc. For example:
5858
59- ``` python
59+ ``` pycon
6060>>> with httpx.Client() as client:
6161... r = client.get(' https://example.com' )
6262...
@@ -68,7 +68,7 @@ These methods accept the same arguments as `httpx.get()`, `httpx.post()`, etc. T
6868
6969For example, to send a request with custom headers:
7070
71- ``` python
71+ ``` pycon
7272>>> with httpx.Client() as client:
7373... headers = {' X-Custom' : ' value' }
7474... r = client.get(' https://example.com' , headers = headers)
@@ -83,7 +83,7 @@ Clients allow you to apply configuration to all outgoing requests by passing par
8383
8484For example, to apply a set of custom headers _ on every request_ :
8585
86- ``` python
86+ ``` pycon
8787>>> url = ' http://httpbin.org/headers'
8888>>> headers = {' user-agent' : ' my-app/0.0.1' }
8989>>> with httpx.Client(headers = headers) as client:
@@ -99,7 +99,7 @@ When a configuration option is provided at both the client-level and request-lev
9999
100100- For headers, query parameters and cookies, the values are combined together. For example:
101101
102- ``` python
102+ ``` pycon
103103>>> headers = {' X-Auth' : ' from-client' }
104104>>> params = {' client_id' : ' client1' }
105105>>> with httpx.Client(headers = headers, params = params) as client:
@@ -117,7 +117,7 @@ URL('https://example.com?client_id=client1&request_id=request1')
117117
118118- For all other parameters, the request-level value takes priority. For example:
119119
120- ``` python
120+ ``` pycon
121121>>> with httpx.Client(auth = (' tom' , ' mot123' )) as client:
122122... r = client.get(' https://example.com' , auth = (' alice' , ' ecila123' ))
123123...
@@ -135,7 +135,7 @@ Additionally, `Client` accepts some configuration options that aren't available
135135
136136For example, ` base_url ` allows you to prepend an URL to all outgoing requests:
137137
138- ``` python
138+ ``` pycon
139139>>> with httpx.Client(base_url = ' http://httpbin.org' ) as client:
140140... r = client.get(' /headers' )
141141...
@@ -232,15 +232,15 @@ not defined, HTTPX tries to add auth into request's header from .netrc file.
232232 you should create a new client or restart the interpreter.
233233
234234As default ` trust_env ` is true. To set false:
235- ``` python
235+ ``` pycon
236236>>> httpx.get(' https://example.org/' , trust_env = False )
237237```
238238
239239If ` NETRC ` environment is empty, HTTPX tries to use default files.
240240(` ~/.netrc ` , ` ~/_netrc ` )
241241
242242To change ` NETRC ` environment:
243- ``` python
243+ ``` pycon
244244>>> import os
245245>>> os.environ[" NETRC" ] = " my_default_folder/.my_netrc"
246246```
@@ -572,7 +572,7 @@ As mentioned in the [quickstart](/quickstart#sending-multipart-file-uploads)
572572multipart file encoding is available by passing a dictionary with the
573573name of the payloads as keys and either tuple of elements or a file-like object or a string as values.
574574
575- ``` python
575+ ``` pycon
576576>>> files = {' upload-file' : (' report.xls' , open (' report.xls' , ' rb' ), ' application/vnd.ms-excel' )}
577577>>> r = httpx.post(" https://httpbin.org/post" , files = files)
578578>>> print (r.text)
@@ -597,7 +597,7 @@ on the file name, with unknown file extensions defaulting to "application/octet-
597597If the file name is explicitly set to ` None ` then HTTPX will not include a content-type
598598MIME header field.
599599
600- ``` python
600+ ``` pycon
601601>>> files = {' upload-file' : (None , ' text content' , ' text/plain' )}
602602>>> r = httpx.post(" https://httpbin.org/post" , files = files)
603603>>> print (r.text)
@@ -620,7 +620,7 @@ You can also send multiple files in one go with a multiple file field form.
620620To do that, pass a list of ` (field, <file>) ` items instead of a dictionary, allowing you to pass multiple items with the same ` field ` .
621621For instance this request sends 2 files, ` foo.png ` and ` bar.png ` in one request on the ` images ` form field:
622622
623- ``` python
623+ ``` pycon
624624>>> files = [(' images' , (' foo.png' , open (' foo.png' , ' rb' ), ' image/png' )),
625625 ('images', ('bar.png', open('bar.png', 'rb'), 'image/png'))]
626626>>> r = httpx.post(" https://httpbin.org/post" , files = files)
@@ -742,7 +742,7 @@ r = httpx.get("https://example.org", verify="path/to/client.pem")
742742
743743Alternatively, you can pass a standard library ` ssl.SSLContext ` .
744744
745- ``` python
745+ ``` pycon
746746>>> import ssl
747747>>> import httpx
748748>>> context = ssl.create_default_context()
@@ -753,15 +753,15 @@ Alternatively, you can pass a standard library `ssl.SSLContext`.
753753
754754We also include a helper function for creating properly configured ` SSLContext ` instances.
755755
756- ``` python
756+ ``` pycon
757757>>> context = httpx.create_ssl_context()
758758```
759759
760760The ` create_ssl_context ` function accepts the same set of SSL configuration arguments
761761(` trust_env ` , ` verify ` , ` cert ` and ` http2 ` arguments)
762762as ` httpx.Client ` or ` httpx.AsyncClient `
763763
764- ``` python
764+ ``` pycon
765765>>> import httpx
766766>>> context = httpx.create_ssl_context(verify = " /tmp/client.pem" )
767767>>> httpx.get(' https://example.org' , verify = context)
@@ -796,7 +796,7 @@ If you do need to make HTTPS connections to a local server, for example to test
7967961 . Pass the server key/cert files when starting your local server. (This depends on the particular web server you're using. For example, [ Uvicorn] ( https://www.uvicorn.org ) provides the ` --ssl-keyfile ` and ` --ssl-certfile ` options.)
7977971 . Tell HTTPX to use the certificates stored in ` client.pem ` :
798798
799- ``` python
799+ ``` pycon
800800>>> import httpx
801801>>> r = httpx.get(" https://localhost:8000" , verify = " /tmp/client.pem" )
802802>>> r
@@ -814,7 +814,7 @@ class directly, and pass it to the client instance. The `httpcore` package
814814provides a ` local_address ` configuration that is only available via this
815815low-level API.
816816
817- ``` python
817+ ``` pycon
818818>>> import httpx, httpcore
819819>>> ssl_context = httpx.create_ssl_context()
820820>>> transport = httpcore.SyncConnectionPool(
@@ -854,7 +854,7 @@ HTTPX also currently ships with a transport that uses the excellent
854854[ ` urllib3 ` library] ( https://urllib3.readthedocs.io/en/latest/ ) , which can be
855855used with the sync ` Client ` ...
856856
857- ``` python
857+ ``` pycon
858858>>> import httpx
859859>>> client = httpx.Client(transport = httpx.URLLib3Transport())
860860>>> client.get(" https://example.org" )
@@ -891,7 +891,7 @@ class HelloWorldTransport(httpcore.SyncHTTPTransport):
891891
892892Which we can use in the same way:
893893
894- ``` python
894+ ``` pycon
895895>>> import httpx
896896>>> client = httpx.Client(transport = HelloWorldTransport())
897897>>> response = client.get(" https://example.org/" )
0 commit comments