cyberjunky / python-garminconnect

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

Login returns security error #75

Closed imagineering-uk closed 2 years ago

imagineering-uk commented 2 years ago

When running from bash, the script executes, but Garmin appears to be blocking logins. It worked the very first time, but 20 seconds later it returned this as part of the HTML response in the shell.

This website is using a security service to protect itself from online attacks.

ERROR:main:Error occurred during Garmin Connect communication: Forbidden url: https://sso.garmin.com/sso/signin

Any thoughts? It did work the very first time it ran. Thanks

imagineering-uk commented 2 years ago

This is my code, as I stripped it right down to just want steps...

#!/usr/bin/env python3
import logging
import datetime

from garminconnect import (
    Garmin,
    GarminConnectConnectionError,
    GarminConnectTooManyRequestsError,
    GarminConnectAuthenticationError,
)

# Configure debug logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)

# Example dates
today = datetime.date.today()
lastweek = today - datetime.timedelta(days=7)

try:
    # API

    ## Initialize Garmin api with your credentials
    api = Garmin("**********", "***********")

    ## Login to Garmin Connect portal
    api.login()

    # USER STATISTICS LOGGED

    ## Get steps data for today 'YYYY-MM-DD'
    logger.info(api.get_steps_data(today.isoformat()))

    ## Logout of Garmin Connect portal
    api.logout()

except (
        GarminConnectConnectionError,
        GarminConnectAuthenticationError,
        GarminConnectTooManyRequestsError,
    ) as err:
    logger.error("Error occurred during Garmin Connect communication: %s", err)
imagineering-uk commented 2 years ago

Im going to close this issue, trying again it appears that it maybe from garmin side, where they dont allow many requests within a certain period of time. New day and it ran fine, tried again after 1 minute and got the error again. Will attempt again tomorrow and see if that is the issue.

imagineering-uk commented 2 years ago

Sorry, still getting the same issue after 8 hours. Any thoughts?

bhi5hmaraj commented 2 years ago

+1 I am getting the same error

julianlatasa commented 2 years ago

Garmin block the login after a number of consecutives logins in certain time. I just implemented session saving to avoid this, and reuse sessions.

leeen82 commented 2 years ago

I tried the saved session but am not seeing api.session_data field. Anyone having the same issue? Just did pip install for latest version.

julianlatasa commented 2 years ago

@leeen82 thats because the lastest changes, has not been updated in the pip package. If you want to try it, just download the module and use the local module file, until the package is realased.

cyberjunky commented 2 years ago

I have created package version 0.1.45