Skip to content

Instantly share code, notes, and snippets.

@tianweidut
Created June 18, 2013 03:26
Show Gist options
  • Save tianweidut/5802482 to your computer and use it in GitHub Desktop.
Save tianweidut/5802482 to your computer and use it in GitHub Desktop.
Python Http Basic Authorization
import urllib2,base64
url = "http://192.168.2.90:7878/api/users/?format=json"
request = urllib2.Request(url)
username = "root"
password = "root"
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
result = urllib2.urlopen(request)
result.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment