Created
April 9, 2014 11:02
-
-
Save dobe/10255132 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def download(url, filepath): | |
print "downloading %s to %s" % (url, filepath) | |
parts = urlparse(url) | |
login, account, password = netrc.netrc().authenticators(parts.netloc) | |
request = urllib2.Request(url) | |
creds = base64.encodestring('%s:%s' % (login, password)).strip() | |
request.add_header("Authorization", "Basic %s" % creds) | |
result = urllib2.urlopen(request) | |
assert result.getcode() == 200 | |
f = open(filepath, 'wb') | |
f.write(result.read()); | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment