Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
oktaykurt opened this issue Oct 3, 2024 · 1 comment

Comments

@oktaykurt
Copy link

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

  • Operating System: macOS (MacBook Air)
  • Python Version: 3.11.5 (installed via Homebrew)
  • Installation Method: Installed via Homebrew
  • Internet Connection: Stable and verified
  • Garmin Account: Credentials are correct; able to log in via the web interface

What I've Tried

  • Updated the garth library using pip install --upgrade garth
  • Ensured that garmindb_cli.py is up to date
  • Verified Garmin account credentials
  • Checked for any API changes or updates in the garth repository
  • Inspected the response manually to see if an HTML error page is returned instead of JSON
  • Searched for similar issues but didn't find a solution

Possible Cause

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

  • Changes in Garmin's API endpoints or authentication methods
  • An authentication failure that returns an HTML error page instead of JSON
  • A need to update the script to handle non-JSON responses gracefully
@tcgoetz
Copy link
Owner

tcgoetz commented Nov 2, 2024

You should file a garth bug for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants