Skip to content

Instantly share code, notes, and snippets.

@skinp
Created January 11, 2013 02:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skinp/4507414 to your computer and use it in GitHub Desktop.
Save skinp/4507414 to your computer and use it in GitHub Desktop.
Python basic auth using urllib2
import urllib2, base64
request = urllib2.Request("http://api.url")
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
result = urllib2.urlopen(request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment