Skip to content

Instantly share code, notes, and snippets.

@rlcarrca
Created August 3, 2015 01:22
Show Gist options
  • Save rlcarrca/de5c840c1caf0d750515 to your computer and use it in GitHub Desktop.
Save rlcarrca/de5c840c1caf0d750515 to your computer and use it in GitHub Desktop.
Checking basic authentication
import urllib2, base64
(user, password) = ('ben', 'xyz')
request = urllib2.Request("http://localhost:8080/")
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
result = urllib2.urlopen(request)
print result.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment