Skip to content

Instantly share code, notes, and snippets.

@jackperry
Created February 11, 2011 10:16
Show Gist options
  • Save jackperry/822168 to your computer and use it in GitHub Desktop.
Save jackperry/822168 to your computer and use it in GitHub Desktop.
Found from Google. Saving here.
import urllib2, base64
request = urllib2.Request('url')
base64string = base64.encodestring('%s:%s' % ('user', 'password'))[:-1]
request.add_header("Authorization", "Basic %s" % base64string)
htmlFile = urllib2.urlopen(request)
htmlData = htmlFile.read()
print htmlData
htmlFile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment