Created
April 25, 2012 09:10
-
-
Save slingamn/2488388 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
def httpbin(*suffix): | |
"""Returns url for HTTPBIN resource.""" | |
return 'http://httpbin.org/' + '/'.join(suffix) | |
s = requests.session() | |
r = s.get(httpbin('cookies', 'set', 'a', '97')) | |
assert json.loads(r.text)['cookies'] == {'a': '97'} | |
c = requests.get(httpbin('cookies', 'set', 'c', '99')).cookies | |
# merge in the cookie with value 'c': | |
r = s.get(httpbin('cookies'), cookies=c) | |
assert json.loads(r.text)['cookies'], {'a': '97', 'c': '99'} | |
r = s.get(httpbin('cookies')) | |
# should this print 'a' and 'c', or just 'a'? | |
# currently prints 'a' and 'c' | |
print json.loads(r.text)['cookies'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a and c is correct.
To not send a cookie, you should be able to do this: