Skip to content

Instantly share code, notes, and snippets.

@kissgyorgy
Created July 29, 2013 08:03
Show Gist options
  • Select an option

  • Save kissgyorgy/6102786 to your computer and use it in GitHub Desktop.

Select an option

Save kissgyorgy/6102786 to your computer and use it in GitHub Desktop.
Python: Add cookies to a request with urllib2
# see: http://stackoverflow.com/a/3334959/720077
# if there are more cookies, they should go all in one "Cookie" header in this format:
# "cookie1name=cookie1value;cookie2name=cookie2value;"
import urllib2
opener = urllib2.build_opener()
opener.addheaders.append(('Cookie', 'cookiename=cookievalue'))
f = opener.open("http://example.com/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment