tcgoetz / GarminDB

Download and parse data from Garmin Connect or a Garmin watch, FitBit CSV, and MS Health CSV files into and analyze data in Sqlite serverless databases with Jupyter notebooks.
GNU General Public License v2.0
1.18k stars 142 forks source link

JSONDecodeError when running garmindb_cli.py: requests.exceptions.JSONDecodeError: Expecting value #245

Open oktaykurt opened 1 month ago

oktaykurt commented 1 month ago

Bug Report

Describe the bug
I'm encountering a JSONDecodeError when trying to download data using garmindb_cli.py. The script fails during the JSON parsing of a response from the server.

To Reproduce
Steps to reproduce the behavior:

  1. Run the command:
    garmindb_cli.py --all --download
  2. Observe the error output.

Expected behavior
I expected the script to successfully download all data without errors.

Logs
Please find below the output and traceback:

___Downloading All Data___
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/requests/models.py", line 974, in json
    return complexjson.loads(self.text, **kwargs)
  File "/opt/homebrew/Cellar/python@3.11/3.11.5/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/opt/homebrew/Cellar/python@3.11/3.11.5/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/opt/homebrew/Cellar/python@3.11/3.11.5/lib/python3.11/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)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/bin/garmindb_cli.py", line 368, in <module>
    main(sys.argv[1:])
  File "/opt/homebrew/bin/garmindb_cli.py", line 349, in main
    download_data(args.overwrite, args.latest, args.stats)
  File "/opt/homebrew/bin/garmindb_cli.py", line 113, in download_data
    if not download.login():
           ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/garmindb/download.py", line 92, in login
    self.garth.username
  File "/opt/homebrew/lib/python3.11/site-packages/garth/http.py", line 109, in username
    return self.profile["userName"]
           ^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/garth/http.py", line 101, in profile
    self._profile = self.connectapi(
                    ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/garth/http.py", line 171, in connectapi
    resp = self.request(method, "connectapi", path, api=True, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/garth/http.py", line 129, in request
    self.refresh_oauth2()
  File "/opt/homebrew/lib/python3.11/site-packages/garth/http.py", line 168, in refresh_oauth2
    self.oauth2_token = sso.exchange(self.oauth1_token, self)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/garth/sso.py", line 146, in exchange
    ).json()
      ^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/requests/models.py", line 978, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Additional context

What I've Tried

Possible Cause

It seems the script is expecting a JSON response but is receiving an unexpected response from the server, possibly due to:

tcgoetz commented 5 days ago

You should file a garth bug for this.