Skip to content
Myr

Document use of sessions as context managers.

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

authored by Lukas Graf · committed by Lukas Graf · parent 9b067db · Browse files · 2 files+15 added−0 removed
This commit

State

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

Diff stats

2 files+15 added−0 removed

  • other:+15 added−0 removed

2 files+15 added−0 removed

modified:docs/user/advanced.rst+9 added
40 unmodified lines
41Any dictionaries that you pass to a request method will be merged with the42session-level values that are set. The method-level parameters override session43parameters.4445Sessions can also be used as context managers::4647 with requests.Session() as s:48 s.get('http://httpbin.org/cookies/set/sessioncookie/123456789')4950This will make sure the session is closed as soon as the ``with`` block is51exited, even if unhandled exceptions occured.525354.. admonition:: Remove a Value From a Dict Parameter5556 Sometimes you'll want to omit session-level keys from a dict parameter. To57 do this, you simply set that key's value to ``None`` in the method-level
783 unmodified lines
modified:requests/sessions.py+6 added
273 unmodified lines
274 >>> import requests275 >>> s = requests.Session()276 >>> s.get('http://httpbin.org/get')277 200278279 Or as a context manager::280281 >>> with requests.Session() as s:282 >>> s.get('http://httpbin.org/get')283 200284 """285286 __attrs__ = [287 'headers', 'cookies', 'auth', 'proxies', 'hooks', 'params', 'verify',
396 unmodified lines