nsidc / earthaccess

Python Library for NASA Earthdata APIs
https://earthaccess.readthedocs.io/
MIT License
416 stars 83 forks source link

[BUG] case of automatic token refresh failure #848

Open itcarroll opened 1 week ago

itcarroll commented 1 week ago

Is this issue already tracked somewhere, or is this a new report?

Current Behavior

My EDL token is not getting refreshed.

import earthaccess
auth = earthaccess.login()
earthaccess.search_datasets(instrument="oci")
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
File [/srv/conda/envs/notebook/lib/python3.10/site-packages/earthaccess/search.py:86](https://oss.oel.smce.nasa.gov/srv/conda/envs/notebook/lib/python3.10/site-packages/earthaccess/search.py#line=85), in DataCollections.hits(self)
     85 try:
---> 86     response.raise_for_status()
     87 except requests.exceptions.HTTPError as ex:

File [/srv/conda/envs/notebook/lib/python3.10/site-packages/requests/models.py:1021](https://oss.oel.smce.nasa.gov/srv/conda/envs/notebook/lib/python3.10/site-packages/requests/models.py#line=1020), in Response.raise_for_status(self)
   1020 if http_error_msg:
-> 1021     raise HTTPError(http_error_msg, response=self)

HTTPError: 401 Client Error: Unauthorized for url: https://cmr.earthdata.nasa.gov/search/collections.umm_json?has_granules=true&include_granule_counts=true&instrument=oci&page_size=0

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
Cell In[1], line 3
      1 import earthaccess
      2 auth = earthaccess.login()
----> 3 earthaccess.search_datasets(instrument="oci")

File /srv/conda/envs/notebook/lib/python3.10/site-packages/earthaccess/api.py:80, in search_datasets(count, **kwargs)
     78 else:
     79     query = DataCollections().parameters(**kwargs)
---> 80 datasets_found = query.hits()
     81 logger.info(f"Datasets found: {datasets_found}")
     82 if count > 0:

File [/srv/conda/envs/notebook/lib/python3.10/site-packages/earthaccess/search.py:88](https://oss.oel.smce.nasa.gov/srv/conda/envs/notebook/lib/python3.10/site-packages/earthaccess/search.py#line=87), in DataCollections.hits(self)
     86     response.raise_for_status()
     87 except requests.exceptions.HTTPError as ex:
---> 88     raise RuntimeError(ex.response.text) from ex
     90 return int(response.headers["CMR-Hits"])

RuntimeError: {"errors":["Token [Bearer eyJXXXX_0FQ] has expired. Note the token value has been partially redacted."]}

Expected Behavior

My EDL token is expired, and I was expecting earthaccess to generate a new token for me (because #764 was purportedly fixed).

Steps To Reproduce

Wait until your EDL token expires ... then try the above.

Environment

- OS: Ubuntu 22.04.5 LTS
- Python: 3.10.14
- earthaccess installed from git commit 9784e4cee01a9d8d7514faea11cd3b80a12ae40f

Additional Context

No response

chuckwondo commented 1 week ago

This does seem strange, particularly since I believe that about a month and a half ago, I had confirmed that this automatically created a new token for me, as my EDL token had also expired at that point.

Have you created a new token yet? If not, I have something I'd like you to do to help us debug this.

itcarroll commented 1 week ago

Alas, I had to carry on, and created a new token. I can try what you'd like me to do on ... 12/25/2024. Or maybe someone else will experience this sooner and can try, so do tell.

chuckwondo commented 1 week ago

Alas, I had to carry on, and created a new token. I can try what you'd like me to do on ... 12/25/2024. Or maybe someone else will experience this sooner and can try, so do tell.

No worries. Mine expires on 11/11, so I'll set a reminder for myself to come back to this on 11/12, just to be sure it is expired.