cyberjunky / python-garminconnect

Python 3 API wrapper for Garmin Connect to get activity statistics
MIT License
965 stars 151 forks source link

Error if no HRV Data is available. #138

Closed littleyoda closed 1 year ago

littleyoda commented 1 year ago

In the first days of using a new device, the HRV data is not available. During this time, the library unfortunately crashes with the following error message.

DEBUG:urllib3.connectionpool:https://connect.garmin.com:443 "GET /modern/proxy/hrv-service/hrv/%7B'2023-04-22T09:45:37.270685'%7D HTTP/1.1" 500 None

Traceback (most recent call last):
  File "/home/sven/devel/DataMining/python-garminconnect/my.py", line 484, in <module>
    out["hrv"] = api.get_hrv_data({today.isoformat()})
  File "/home/sven/devel/DataMining/python-garminconnect/garminconnect/__init__.py", line 653, in get_hrv_data
    return self.modern_rest_client.get(url).json()
AttributeError: 'NoneType' object has no attribute 'json'
psdupvi commented 1 year ago

I think most of these will error out if the data isn't available. There are currently no (maybe a few?) try/except blocks.

I'm not sure if that's a design choice by @cyberjunky or if we wanted to add those blocks in everywhere.

It may make more sense to point it out in the Readme and have people who use the package catch those errors instead

cyberjunky commented 1 year ago

@psdupvi or we must try to assign the json and return it in the client_get routine itself and add a except there. but that means a rather big change since not all calls return json. >Need to think this over

cyberjunky commented 1 year ago

@littleyoda Can you try latest version, and let me know if this is solved? If not you can also maybe add a try: except AttributeError: around your call to catch it.

matin commented 1 year ago

@cyberjunky This is already resolved. See #157