Issue with EDL token usage
Posted: Tue Oct 29, 2024 7:28 am America/New_York
I am trying to get started using the API using the EDL token I just generated on Nasa's Earthdata page. However, I tried running this code as a test and get the following error:
from pydap.client import open_url
import requests
import os
dataset_url = 'https://opendap.earthdata.nasa.gov/collections/C1276812863-GES_DISC/granules/M2T1NXSLV.5.12.4%3AMERRA2_100.tavg1_2d_slv_Nx.19800101.nc4?dap4.ce=/T2M[0:1:23][0:1:360][0:1:575]'
token_file_path = os.path.join(os.path.expanduser("~"), ".edl_token")
with open(token_file_path, 'r') as token_file:
token = token_file.read().strip()
my_session = requests.Session()
my_session.headers={"Authorization": token}
try:
dataset = open_url(dataset_url, session=my_session, protocol="dap4")
print(dataset['T2M'][:])
except OSError as e:
print('Error', e)
print('Please check that your .edl_token file has been properly generated, and that your .dodsrc files are in their correct locations.')
Error message:
HTTPError: 401 Unauthorized
Credentials (username, password) are invalid
This is happening even though the token is correct and stored in the correct folder on my Mac. Any help is greatly appreciated!
from pydap.client import open_url
import requests
import os
dataset_url = 'https://opendap.earthdata.nasa.gov/collections/C1276812863-GES_DISC/granules/M2T1NXSLV.5.12.4%3AMERRA2_100.tavg1_2d_slv_Nx.19800101.nc4?dap4.ce=/T2M[0:1:23][0:1:360][0:1:575]'
token_file_path = os.path.join(os.path.expanduser("~"), ".edl_token")
with open(token_file_path, 'r') as token_file:
token = token_file.read().strip()
my_session = requests.Session()
my_session.headers={"Authorization": token}
try:
dataset = open_url(dataset_url, session=my_session, protocol="dap4")
print(dataset['T2M'][:])
except OSError as e:
print('Error', e)
print('Please check that your .edl_token file has been properly generated, and that your .dodsrc files are in their correct locations.')
Error message:
HTTPError: 401 Unauthorized
Credentials (username, password) are invalid
This is happening even though the token is correct and stored in the correct folder on my Mac. Any help is greatly appreciated!