Closed jgomezdans closed 7 years ago
Bummer, I need to update my local copy to the latest version (which is the 3.5 compatilbe version... groan)
Hi, I'm not sure on how to use GitHub without causing damages. However, here is my attempt to manage Earthdata login credentials. I use Python 2.7 on OSX 10.9. I'm going to merge this into your script. Btw, which is the latest version?
# Import modules
from getpass import get pass
from base64 import b64encode
import urllib2
from shutil import copyfileobj
# Read login credentials and prepare authorisation string
username = raw_input( 'User name: ' )
password = getpass()
authstring = b64encode( '%s:%s' % (username, password) )
# Prepare opener
cookieprocessor = urllib2.HTTPCookieProcessor()
opener = urllib2.build_opener( cookieprocessor )
# Prepare request
fileurl = 'http://e4ftl01.cr.usgs.gov/MOLA/MYD09A1.006/2016.08.20/MYD09A1.A2016233.h19v05.006.2016243125358.hdf'
request = urllib2.Request( fileurl )
# Add authorisation header to request
request.add_header( 'Authorization', 'Basic %s' % authstring )
# Download file
localfilepath = './MYD09A1.A2016233.h19v05.006.2016243125358.hdf'
remotefile = opener.open( request )
with open( localfilepath, 'wb' ) as local file
copyfileobj( remotefile, localfile )
Carmine, note that release 1.3.2 now works with EarthData logins. Make sure you get this release, 1.3.1 had a stupid bug in it ;-)
You need to install the requests
package (pip install requests
or use anaconda)
I'm closing this as the code now works for me!
So, NASA now requires usernames and passwords.