Skip to content
Myr

docs update

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Kenneth Reitz · committed by Kenneth Reitz · parent e477fce · Browse files · 1 file+36 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+36 added−10 removed

  • other:+36 added−10 removed

1 file+36 added−10 removed

modified:docs/user/advanced.rst+36 added-10 removed
1 unmodified line
23Advanced Usage4==============56This document covers more advanced features.6This document covers some of Requests more advanced features.789Session Objects9===============10---------------1111.. module:: requests.session 12The Session object allows you to persist certain parameters across13requests. It also establishes a CookieJar and passes it along14to any requests made from the Session instance.1513The Session object allows you to persist certain parameters across requests. It also establishes a CookieJar by default and passes it along in any requests made from the Session instance. For a complete list of allowed parameters, please see the *__attrs__* field in *requests/session.py*. ::16A session object has all the methods of the main Requests API.1715 from requests.session import Session18Let's persist some cookies across requests::1917 s = Session()18 s.get("http://httpbin.org/cookies/set/sessioncookie/123456789")19 r = s.get("http://httpbin.org/cookies")20 print r.content20 with requests.session() as s:2122Note: Certain parameters are best set at the request.config level (i.e. a global proxy, user agent header).22 s.get('http://httpbin.org/cookies/set/sessioncookie/123456789')23 r = s.get("http://httpbin.org/cookies")2425 print r.content262728Sessions can also be used to provide default data to the request methods::2930 headers = {'x-test': 'true'}31 auth = ('user', 'pass')3233 with requests.session(auth=auth, headers=headers) as c:3435 # both 'x-test' and 'x-test2' are sent36 c.get('http://httpbin.org/headers', header={'x-test2', 'true'})373839.. admonition:: Global Settings4041 Certain parameters are best set at the ``request.config`` level42 (e.g.. a global proxy, user agent header).434445Event Hooks46-----------4748Requests has a hook system that allows you . This is useful for