La0 / garmin-uploader

Garmin Connect Python Uploader
GNU General Public License v2.0
124 stars 30 forks source link

Authentication Failures again #28

Open philosowaffle opened 3 years ago

philosowaffle commented 3 years ago

Howdy,

Seems Garmin has yet again tweaked some things and I have several users (including myself) running into auth failures. https://github.com/philosowaffle/peloton-to-garmin/issues/109

assert self.user.authenticate(), "Failed to authenticate garmin user."
AssertionError: Failed to authenticate garmin user.

Thank you in advance for any help!

La0 commented 3 years ago

Hey @philosowaffle ,

I reproduce the issue: the project unit tests are failing on the authentication.

I'll try to quickly find a fix, I'll keep you posted here

La0 commented 3 years ago

This time it's Cloudflare rejecting the requests.

I get a nice error page, with the infamous 1020 Cloudflare error. This may take some time to fix...

Screenshot 2021-05-18 at 17-53-28 Garmin Maintenance

philosowaffle commented 3 years ago

Oh no :(

Cloudflare is awesome for keeping our favorite sites online, but as an indy dev who just wants to automate things, I hate it lol

La0 commented 3 years ago

You can try this rough patch : https://github.com/La0/garmin-uploader/pull/29/files

I got some auth requests to work with this code, but now i'm getting HTTP 429 Too many requests :sob:

philosowaffle commented 3 years ago

Thank you for the quick patch attempt! I'm at work so won't be able to verify till tonight.

On the 429 error, I've had good luck with switching onto a VPN. The 429 seems tied to IP address, so if you hop on a vpn then you get another 10-20 requests before it throws 429 again. And I think the cool off period is about 1hr.

kenlpeters commented 3 years ago

How can we pull this fix. I would like to test it.

Abasz commented 3 years ago

I had similar problem with my code. Actually itis the cloudflare protection that kicks in. I got it working using cloudscraper library to make the request. Here is a similar py libarary where this is duscussed.

https://github.com/cyberjunky/python-garminconnect/issues/46

BebeMischa commented 3 years ago

i can confirm Cyberjunky fix looks like its working, I'm testing it live now

La0 commented 3 years ago

@kenlpeters You can try my patch with the following pip command:

pip install https://github.com/La0/garmin-uploader/archive/fix-cloudfare-errors.zip
kenlpeters commented 3 years ago

Still get authentication failed. Not even too many requests

philosowaffle commented 3 years ago

I checked out fix-cloudfare-errors, switched conftest.py to use my dev credentials, then ran the unit tests. Unfortunately, most are still failing with Authentication Failed. Same error if I use the default guploader creds as well.

BebeMischa commented 3 years ago

Double integration (two accounts on one HA instance) running OK for more than 3 hours now, see

https://github.com/home-assistant/core/issues/50822

La0 commented 3 years ago

I'll try clouscrapper tommorow

La0 commented 3 years ago

The CI is ok on the current branch, except on Python 3.7 :man_shrugging:

kenlpeters commented 3 years ago

@La0 - let me know when 3.7 is working. Unfortunately that is the version I am running... go figure.

La0 commented 3 years ago

@kenlpeters I just re-ran the CI, and it worked. I get the same results locally on multiple Python versions, and on multiple accounts / servers.

Please test this version !

kenlpeters commented 3 years ago

I must not be downloading the proper version of the api.py. Can you link the right version.

kenlpeters commented 3 years ago

Any update on this. I am still running into the authentication error. I just think it is a fact that I am not pulling the proper version of the software.

superm1 commented 3 years ago

@kenlpeters I just re-ran the CI, and it worked. I get the same results locally on multiple Python versions, and on multiple accounts / servers.

Please test this version !

It's working for me now thanks!

kenlpeters commented 3 years ago

Great how to get the newest version.

superm1 commented 3 years ago

Any update on this. I am still running into the authentication error. I just think it is a fact that I am not pulling the proper version of the software.

For me I had the old version installed in ~/.local and nothing else there. So I removed all of that directory, then cloned this repo, switched branches and ran

python3 setup.py install --user
kenlpeters commented 3 years ago

Little out of my league.  Is there a link to the newest branch/repo to download On May 20, 2021, 7:57 AM -0400, Mario Limonciello @.***>, wrote:

Any update on this. I am still running into the authentication error. I just think it is a fact that I am not pulling the proper version of the software. For me I had the old version installed in ~/.local and nothing else there. So I removed all of that directory, then cloned this repo, switched branches and ran python3 setup.py install --user — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

kenlpeters commented 3 years ago

I think I downloaded the proper branch (cloud fare fixes) and unzipped and run the setup.py. Still I am getting Authenication error.

kenlpeters commented 3 years ago

I tried the CI branch as well and it did not work. So obviously I am downloading the right branch.

superm1 commented 3 years ago

I think I downloaded the proper branch (cloud fare fixes) and unzipped and run the setup.py. Still I am getting Authenication error.

Assuming you're not hitting a different failure and are running the wrong code still - if I was to guess, you're still getting the wrong copy from a local install somewhere else that has higher precedence (like site-packages or dist-packages). You should try doing pip uninstall garmin-uploader.

kenlpeters commented 3 years ago

Did you download the cloud fare fixes branch?

superm1 commented 3 years ago

Yes. Basically I did:

rm ~/.local -r
git clone https://github.com/La0/garmin-uploader/
git checkout fix-cloudfare-errors
python3 setup.py install --user
gupload .....

and verified it's working for me now.

philosowaffle commented 3 years ago

Another option, if you do not want to bother with installing/uninstalling packages:

> git clone https://github.com/La0/garmin-uploader/
> git checkout fix-cloudfare-errors
> pip install -r requirements.txt
> pip install -r requirements-tests.txt
> cd tests
> pytest 

This runs the unit tests with a default set of credentials. If you would like to try running the unit tests with your personal credentials then modify here.

@La0 , assuming what I have outlined above is correct, I am still seeing Authentication failures :(

It fails the check on line 134 in api.py and raises the Authentication failed. exception (which bubbles up and is masked by the Invalid Credentials exception). Fails for both your test user and my with my user creds. I am on python 3.6.4.

@superm1 pardon snooping on your GH account, but looks like you're based in Texas. I am also based in Texas, so I guess that rules out different regional rules CloudFlare could be enforcing.

kenlpeters commented 3 years ago

So I am not getting invalid credentials even though my credentials are correct.

kenlpeters commented 3 years ago

@philosowaffle - Same here. Python 3.7 invalid credentials both with default and my person ones.

superm1 commented 3 years ago

It fails the check on line 134 in api.py and raises the Authentication failed. exception (which bubbles up and is masked by the Invalid Credentials exception). Fails for both your test user and my with my user creds. I am on python 3.6.4.

On my side I tried the unit tests with the test user, no problem too. Python 3.8.5 though in case that's mattering.

$ pytest-3
================================================= test session starts ==================================================
platform linux -- Python 3.8.5, pytest-4.6.9, py-1.8.1, pluggy-0.13.0
rootdir: /home/supermario/garmin-uploader
collected 5 items

test_api.py ..                                                                                                   [ 40%]
test_user.py ..                                                                                                  [ 80%]
test_workflow.py .                                                                                               [100%]

=============================================== 5 passed in 6.08 seconds ===============================================

@superm1 pardon snooping on your GH account, but looks like you're based in Texas. I am also based in Texas, so I guess that rules out different regional rules CloudFlare could be enforcing.

Ah glad you did snoop, that was my thought too just now.

grizzls commented 3 years ago

For me the unit test fails using python 3.9.0 in pyenv on Mac

kenlpeters commented 3 years ago

Do we know what versions it does work on?

philosowaffle commented 3 years ago

@kenlpeters This is likely not related to python version since the CI job is passing for multiple CI versions, including 3.7 and superm1 confirmed it works for him on 3.8.5

We are just sharing python info to help identify if any patterns exist.

kenlpeters commented 3 years ago

Cool - if there is anything I can contribute let me know.

kenlpeters commented 3 years ago

Not that it matters but I running Debian on a AWS virtual machine

kenlpeters commented 3 years ago

I found something interesting. When we make the request to sso.garmin.com/sso/signin to get the _csrf. the page that gets returned does not have the code in it because it requires you to be using a browser to have JavaScript enabled. It appears they are checking to see if the browser has javascript and if it doesn't it won't show the screen. This may help.

kenlpeters commented 3 years ago

Guys it just started working for me :)

La0 commented 3 years ago

Hey guys, sorry for the delay.

I'm gonna merge this code and publish a release at it seems to be working at least for some users. Looks like you may be hitting too many requests or a geo-block. i'll investigate cloudscrapper this weekend

La0 commented 3 years ago

garmin-uploader 1.0.10 is now available with this patch.

You can now run:

pip install garmin-uploader=1.0.10
kenlpeters commented 3 years ago

Works great. Except there definitely is a limiter on the number of requests. I wonder what the time frame is before it resets.

philosowaffle commented 3 years ago

Want want to confirm, the patch is still not working for me :( But it is atleast working for some people.

kenlpeters commented 3 years ago

Now it is returning no login form. It seems Garmin is definitely having issue with their SSO

zed4 commented 3 years ago

i, too, am still having issues (Python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32)

grizzls commented 3 years ago

Still no dice on my end either. Would it be worth while doing a wireshark trace or something?

La0 commented 3 years ago

I made a version using cloudscraper, but it seems to work only sometimes... That runs OK on my computer, but Github CI has 4 failures out of 5 runs :sob:

You can try that version using:

pip install https://github.com/La0/garmin-uploader/archive/cloudscraper.zip
kenlpeters commented 3 years ago

For now the original CI (not cloudscraper) is working on AWS node server. So I am going to stick with that. Thanks for all of your hard work getting this back to operational status. I will say it seems to me that Garmin made a change, and slowly allowed regionds/IP schemas to access. It is the only think that makes sense. I hope that the others see it start working.

philosowaffle commented 3 years ago

@La0, thank you for trying the switch to cloudscraper, unfortunately not working for me still😢

dkmcgowan commented 3 years ago

Maybe we make an LLC and try to get approved with the Garmin connect activity api and then the project can have an option to enter commercial creds... It's a pain but it says approval in 2 days, maybe it's a light process

La0 commented 3 years ago

Maybe we make an LLC and try to get approved with the Garmin connect activity api and then the project can have an option to enter commercial creds... It's a pain but it says approval in 2 days, maybe it's a light process

I contacted them about official API support a few years back, and it was only available for a few select users, with deep pockets (from 5 to 10k USD). That may have changed, but even if it was free and easy to setup, every user would have to setup its own app on their website: we would not be able to ship the library with credentials.