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}")
Token API can we still use it?
-
- Posts: 2
- Joined: Sun Dec 03, 2023 11:19 pm America/New_York
Re: Token API can we still use it?
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
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.
-
- Posts: 2
- Joined: Sun Dec 03, 2023 11:19 pm America/New_York
Re: Token API can we still use it?
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?
Re: Token API can we still use it?
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=='}.
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=='}.