Token API can we still use it?
Posted: Sun Dec 03, 2023 11:23 pm America/New_York
I tried to get a token from Earth data using this /api/users/find_or_create_token, but always got error 401. Is there any suggestion to get a token from python
#Combine username and password with a colon
credentials = f"{username}:{password}"
# Encode the combined string to Base64
encoded_credentials = base64.b64encode(credentials.encode("utf-8")).decode("utf-8")
# Create the Basic Authentication header
headers = {'Authorization': f'Basic {encoded_credentials}'}
print(headers)
url = 'https://urs.earthdata.nasa.gov/api/users/find_or_create_token'
response = requests.post(url, headers=headers)
# Check if the request was successful (status code 200)
if response.status_code == 200:
# Parse the HTML content
soup = BeautifulSoup(response.text, 'html.parser')
print(soup)
else:
print(f"Error: {response.status_code}")
#Combine username and password with a colon
credentials = f"{username}:{password}"
# Encode the combined string to Base64
encoded_credentials = base64.b64encode(credentials.encode("utf-8")).decode("utf-8")
# Create the Basic Authentication header
headers = {'Authorization': f'Basic {encoded_credentials}'}
print(headers)
url = 'https://urs.earthdata.nasa.gov/api/users/find_or_create_token'
response = requests.post(url, headers=headers)
# Check if the request was successful (status code 200)
if response.status_code == 200:
# Parse the HTML content
soup = BeautifulSoup(response.text, 'html.parser')
print(soup)
else:
print(f"Error: {response.status_code}")