Token API can we still use it?

Use this Forum to find information on, or ask a question about, NASA Earth Science data.
Post Reply
satapon128254
Posts: 2
Joined: Sun Dec 03, 2023 11:19 pm America/New_York
Answers: 0

Token API can we still use it?

by satapon128254 » 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}")

Tags:

mstartzel
Posts: 5
Joined: Thu Sep 22, 2022 3:06 pm America/New_York
Answers: 0

Re: Token API can we still use it?

by mstartzel » Mon Dec 04, 2023 2:35 pm America/New_York

Hey [mention]satapon128254[/mention]

We've pushed some fixes to this endpoint today; could you try your request again?

I was able to successfully retrieve a token using the same encoding method as you provided - if you still get a 401 response, double check that the username and password you are passing are valid.

Thanks,
Mitch
EDL Ops
Last edited by mstartzel on Mon Dec 04, 2023 2:37 pm America/New_York, edited 1 time in total.

satapon128254
Posts: 2
Joined: Sun Dec 03, 2023 11:19 pm America/New_York
Answers: 0

Re: Token API can we still use it?

by satapon128254 » Tue Dec 05, 2023 8:47 pm America/New_York

Hello and thank you for helping me, I already tried the endpoint again and still get the same error with status code 401. Is the username and password the same as Earth data login?

mstartzel
Posts: 5
Joined: Thu Sep 22, 2022 3:06 pm America/New_York
Answers: 0

Re: Token API can we still use it?

by mstartzel » Wed Dec 06, 2023 2:50 pm America/New_York

Yes, the username and password should be exactly the same as what you use to log in to https://urs.earthdata.nasa.gov/ .

Can you try printing out the response body along with the response code to see the reason for the 401? You should also ensure there are no unexpected headers being added other than the {'Authorization': 'Basic TXN0Y<...>lIQ=='}.

Post Reply