kapadia / usgs

Client library for interfacing with USGS datasets
http://kapadia.github.io/usgs/
ISC License
110 stars 38 forks source link

login error #53

Closed sbrunato closed 3 years ago

sbrunato commented 3 years ago

Hello, I am trying to use 0.3.0, but get an error when trying to login:

>>> from usgs import api
>>> api.login("user","password",save=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sylvain/.virtualenvs/eodag-dev/lib/python3.8/site-packages/usgs/api.py", line 119, in login

  File "/home/sylvain/.virtualenvs/eodag-dev/lib/python3.8/site-packages/usgs/api.py", line 38, in _create_session
    api_key = _get_api_key(api_key)
  File "/home/sylvain/.virtualenvs/eodag-dev/lib/python3.8/site-packages/usgs/api.py", line 22, in _get_api_key
    api_key_info = json.load(f)
  File "/usr/lib/python3.8/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
kapadia commented 3 years ago

Hi @sbrunato - have you previously used this library? When save=True during login, a hidden file is written to the user's home directory, $HOME/.usgs. If that file is lingering from a previous login using an older version, it might trigger the JSON parse error you're seeing.

Can you try deleting the .usgs file if it exists?

sbrunato commented 3 years ago

Thank you very much @kapadia, deleting ~/.usgs fixed the issue