File tree 2 files changed +20
-0
lines changed
2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,8 @@ Status Code Lookup
81
81
>>> requests.codes['\o/']
82
82
200
83
83
84
+ .. _api-cookies :
85
+
84
86
Cookies
85
87
~~~~~~~
86
88
Original file line number Diff line number Diff line change @@ -45,6 +45,24 @@ Any dictionaries that you pass to a request method will be merged with the
45
45
session-level values that are set. The method-level parameters override session
46
46
parameters.
47
47
48
+ Note, however, that method-level parameters will *not * be persisted across
49
+ requests, even if using a session. This example will only send the cookies
50
+ with the first request, but not the second::
51
+
52
+ s = requests.Session()
53
+ r = s.get('http://httpbin.org/cookies', cookies={'from-my': 'browser'})
54
+ print(r.text)
55
+ # '{"cookies": {"from-my": "browser"}}'
56
+
57
+ r = s.get('http://httpbin.org/cookies')
58
+ print(r.text)
59
+ # '{"cookies": {}}'
60
+
61
+
62
+ If you want to manually add cookies to your session, use the
63
+ :ref: `Cookie utility functions <api-cookies >` to manipulate
64
+ :attr: `Session.cookies <requests.Session.cookies> `.
65
+
48
66
Sessions can also be used as context managers::
49
67
50
68
with requests.Session() as s:
You can’t perform that action at this time.
0 commit comments