Skip to content

Instantly share code, notes, and snippets.

@slingamn
Created April 25, 2012 09:10
Show Gist options
  • Save slingamn/2488388 to your computer and use it in GitHub Desktop.
Save slingamn/2488388 to your computer and use it in GitHub Desktop.
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']
@kennethreitz
Copy link

a and c is correct.

To not send a cookie, you should be able to do this:

r = s.get(httpbin('cookies'), cookies={'c': None)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment