cyberjunky / python-garminconnect

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

Can not get sleep data #166

Closed mattia93 closed 10 months ago

mattia93 commented 11 months ago

Hi! I managed to log in (only without tokens though) and get my stats. However, when I call the get_sleep_data function I get this error:

Error occurred during Garmin Connect Client get sleep data: Error in request: 404 Client Error: Not Found

This is my configuration:

python                    3.9.2 
garminconnect             0.2.8 
garth                     0.4.38

I can't understand if the problem is related to Garth, as I also get 401: Unauthorized when logging in with the tokens, or it it's related to the http address. Thank you for your help and for your amazing work

matin commented 11 months ago

I'll take a look tomorrow.

matin commented 11 months ago

@mattia93 My only theory is that displayName and userName for you are different. The garminconnect code uses displayName where it should probably be using userName instead.

Could you run the following Colab and let me know if displayName and userName for you are the same or different?

If they are different for you, that would explain the 401 and is an easy code fix.

matin commented 11 months ago

Here's the Colab: https://colab.research.google.com/gist/matin/69b79211477bbe9b5153b3c1e4a66d6b/username_displayname.ipynb

mattia93 commented 11 months ago

Hi!
They are actually different, the userName value is my email while the displayName is the string that identifies my profile (i.e. https://connect.garmin.com/modern/profile/my-display-name on the web app).
How can I fix this problem? I tried to change displayName to userName but I still get the 404 error. Thanks again for your help

matin commented 11 months ago

How familiar are you with VCR?

I can't reproduce the issue, but if I see the VCR cassettes, it'll be easier.

mattia93 commented 11 months ago

Hi! Thanks again for your help. I installed the vcrpy module and wrapped the get_sleep_data function. I'm attaching the YAML file. I've never used the package before so I hope I did everything correctly. sleep.yaml.zip

matin commented 11 months ago

I'll take a look

matin commented 11 months ago

Here's the URL that's being called in your case: https://connectapi.garmin.com/wellness-service/wellness/dailySleepData/94a151c4-3d2f-473f-9d1f-4f60f0c577ed?date=2023-10-22T00%3A00%3A00&nonSleepBufferMinutes=60

This is clearly not correct: 94a151c4-3d2f-473f-9d1f-4f60f0c577ed

Can you try running this Colab? https://colab.research.google.com/gist/matin/21a1767069b24f627a7c83dfaf503951/garmin-sleep-data.ipynb

That uses your username (instead of displayname) in the URL.

mattia93 commented 11 months ago

Thanks a lot, now it works! I actually found out that the error was in the way the formatting of the date (it was 2023-10-22T00:00:00 instead of being 2023-10-22). I can confirm that it works either with username and with displayname. Thanks again for the help and for the great work

matin commented 11 months ago

Great to hear! Can we close this out?

matin commented 11 months ago

@mattia93 If you like evaluating your sleep data, you should take a look at this Colab that provides some interesting graphs: https://colab.research.google.com/github/matin/garth/blob/main/colabs/sleep.ipynb

matin commented 11 months ago

@cyberjunky this has been resolved and can be closed.