Requests

Sessions

They are there by default even if you don’t use them

s = requests.Session()
s.auth = ('user', 'pass')
s.get('example.com')
s = requests.Session()
s.get('example.com')
len(s.cookies)
2

Connection pooling

requests.get('example.com')
requests.get('example.com')

vs

s = requests.Session()
s.get('example.com')
s.get('example.com')

Transport Adapters

Define how the connections are maintained and they can be tweaked. That’s how you get an SSL adapter

Streaming

r = requests.get(url, stream=True)

[x for  x in r.iter_content(1024])]

or lines

[x for x in r.iter_lines()]

then your response is on r.content

Client certificates

r = requests.get(url, cert=('cert.crt', 'cert.key'))

Unusual auth

last updated on Aug. 9, 2015, 6:02 p.m.
Back