Skip to content

Instantly share code, notes, and snippets.

@dobe
Created April 9, 2014 11:02
Show Gist options
  • Save dobe/10255132 to your computer and use it in GitHub Desktop.
Save dobe/10255132 to your computer and use it in GitHub Desktop.
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