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

Authentication issues with direct uploading TCX files #22

Closed
akramer115 opened this issue Jan 10, 2021 · 30 comments · Fixed by #24
Closed

Authentication issues with direct uploading TCX files #22

akramer115 opened this issue Jan 10, 2021 · 30 comments · Fixed by #24

Comments

@akramer115
Copy link

Hi there-

I'm using the Peloton-to-garmin project to convert Peloton workouts to TCX files with direct uploading to Garmin. We've been experiencing issues with authentication to Garmin - wondering if others are too. I'm receiving this error (and I've triple checked credentials):

2021-01-10 11:31:24,590 [INFO] Try to login on GarminConnect...
2021-01-10 11:31:26,945 [CRITICAL] Login Failure: Login check failed.
Error: Invalid credentials
@philosowaffle
Copy link

These users are on the latest garmin-uploader-1.0.8 version. We seem to have a 50/50 split of people for whom the 1.0.8 version fixed the auth issue (it works for me) and people who are still seeing auth issues.

@amy26point2
Copy link

I'm receiving the same error as @akramer115.

2021-01-11 08:51:46,372 [INFO] Try to login on GarminConnect...
2021-01-11 08:51:47,146 [CRITICAL] Login Failure: Authentification failed.
Error: Invalid credentials

I have no issues signing into the Garmin website.

@stando76
Copy link

upgrading garmin-uploader-1.0.8 fixed the issue for me.

@La0
Copy link
Owner

La0 commented Jan 11, 2021

Hello guys, I read the issue on the peloton-to-garmin project from @philosowaffle , looks like it works... sometimes.

I can't reproduce the issue with several accounts of my own. This may be due to the fact that i hardcode some french localization flags (and Garmin would detect it makes little sense by geo-locating your ip).

The only way for me to debug that issue is if some of you who are affected provide me with their Garmin credentials (after changing the password). I know it's tricky to ask that, but I don't see another easy way

@amy26point2
Copy link

Hi @La0. Thanks so much for the assistance. I can email you my sign on information to test with.

@La0
Copy link
Owner

La0 commented Jan 12, 2021

@amy26point2 Ok, you can send me an email on bastien@nextcairn.com

Here is my GPG public key if you want to send your credentials through an encrypted email.

@La0
Copy link
Owner

La0 commented Jan 12, 2021

@amy26point2 I got your credentials, and they seem to work from my computer 😢

I'll upload a patch to add some diagnostic tooling, so you can try on your own computer. I'll update that issue once i've got something

@amy26point2
Copy link

That is strange. I half expected it to work after I changed my credentials, but I was still getting an error when I tested it. I'll run whatever you need from me. Thanks again!

@daytonbrown
Copy link

Have any of you tried the windows binary .zip? It worked for me after the last updates. Might help with any incompatibilities associated with python versions.

@WhatevsJJ
Copy link

WhatevsJJ commented Jan 12, 2021

This worked for a few weeks then started failing. This is awesome by the way!

EDIT: Auth started failing then I upgraded my uploader and auth is still failing, few more details below:

Old:
pip show garmin-uploader
Name: garmin-uploader
Version: 1.0.7

pip install garmin-uploader --upgrade

New:
pip show garmin-uploader
Name: garmin-uploader
Version: 1.0.8

gupload -u xyz@yahoo.com -p xxxxx -t "running" Output/file.tcx
2021-01-12 12:27:51,032 [INFO] Try to login on GarminConnect...
2021-01-12 12:27:51,930 [CRITICAL] Login Failure: Authentification failed.
Error: Invalid credentials

file.tcx was created by peloton->Garmin uploader - I renamed it for simplicity

Running on Raspberry pi 3
Linux Brain 4.19.79-v7+ #1273 SMP Fri Oct 11 18:13:16 BST 2019 armv7l GNU/Linux

@WhatevsJJ
Copy link

WhatevsJJ commented Jan 12, 2021 via email

@La0
Copy link
Owner

La0 commented Jan 12, 2021

Okay guys, I definetely cannot reproduce the issue on my side, i tried with different servers at different locations: no luck.

Garmin may be sending you different parameters when you login. So we need to use the big guns to solve that issue 🔫

Now bear with me:

  • I'll need to see your network traffic while you login on connect.garmin.com
  • if you share a capture of your interaction with the website, I should be able to see what Garmin is sending you, and why the garmin-uploader lib does not work for you
  • fortunately, all major browsers implement that mechanism, for exactly that purpose (through HAR file)

If you want to help, you'll need to :
0. open a tab in your browser on https://connect.garmin.com and disconnect (if you were connected), you need to be disconnected for the capture to be useful

  1. read those instructions about how to capture your network traffic from your browser (I use firefox, but chrome should be ok too)
  2. Open a new tab in your browser
  3. open devtools (usually F12)
  4. go in the network settings of your devtools
  5. click on Keep logs / Keep journal
  6. now in that tab, load the garmin website https://connect.garmin.com
  7. input your credentials as you normally would
  8. wait for the dashboard to appear (when you are connected)
  9. go back to the devtools, and follow the procedure from the link above to export your capture as an HAR archive file somewhere on your hard drive
  10. upload that file to a file transfer service like https://wetransfer.com/ or something similar
  11. send me an email with that link to bastien@nextcairn.com
  12. ⚠️ do not share that HAR file here, or your credentials will be publicly available !

Thanks for helping, I know it's quite the struggle...

@WhatevsJJ
Copy link

Interesting, I just now created a brand new connect.garmin account to test further and it worked fine on a different computer (VM). So then I tried my real account to upload data and I'll be damn, its working now too as is my wife's account. BOTH were failing earlier today. No idea what changed.

Thanks for this great module.

@akramer115
Copy link
Author

akramer115 commented Jan 13, 2021 via email

@La0
Copy link
Owner

La0 commented Jan 14, 2021

Hello guys,

I received your HAR files, thanks for your help. I did not see some big difference with the current auth, but i made a patch you can try:

pip install https://github.com/La0/garmin-uploader/archive/us-auth.zip

This uses en-us locales, and a few parameters changes, let's see if that works out for you...

@akramer115
Copy link
Author

akramer115 commented Jan 14, 2021 via email

@amy26point2
Copy link

When I performed the install is said all the requirements were already satisfied, so it doesn't look like it changed anything. The error still occurs.

Collecting https://github.com/La0/garmin-uploader/archive/us-auth.zip
Downloading https://github.com/La0/garmin-uploader/archive/us-auth.zip
| 39 kB 416 kB/s
Requirement already satisfied: requests>=2.10.0 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from garmin-uploader==1.0.8) (2.25.0)
Requirement already satisfied: six>=1.10.0 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from garmin-uploader==1.0.8) (1.15.0)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from requests>=2.10.0->garmin-uploader==1.0.8) (1.26.2)
Requirement already satisfied: idna<3,>=2.5 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from requests>=2.10.0->garmin-uploader==1.0.8) (2.10)
Requirement already satisfied: certifi>=2017.4.17 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from requests>=2.10.0->garmin-uploader==1.0.8) (2020.12.5)
Requirement already satisfied: chardet<4,>=3.0.2 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from requests>=2.10.0->garmin-uploader==1.0.8) (3.0.4)

@amy26point2
Copy link

Add me to the list of people it just suddenly started working for again. Thanks so much for the effort!

@philosowaffle
Copy link

Despite this still being a bit of a mystery thanks for going above and beyond to help out @La0. Is there a link we can buy you a coffee at?

@davewongillies
Copy link

davewongillies commented Feb 24, 2021

I've just started hitting on this problem after successfully using garmin-uploader for the last month or so. I've tried the us-auth branch to no avail.

I've started looking into it and added some extra debugging information and got this unexpected result for the headers of the response

2021-02-23 19:39:22,709 [DEBUG] Response from https://connect.garmin.com/modern/
2021-02-23 19:39:22,738 [DEBUG] Response from https://connect.garmin.com/modern/proxy/userprofile-service/socialProfile/
2021-02-23 19:39:23,739 [CRITICAL] Login Failure: 402 Login check failed: 
{
  'Expect-CT': 'max-age=604800,
  report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
  'Content-Length': '0',
  'Vary': 'Accept-Encoding',
  'cf-request-id': '0873a830370000ed87b08e3000000001',
  'Server': 'cloudflare',
  'Connection': 'keep-alive',
  'Date': 'Wed, 24 Feb 2021 03:22:20 GMT',
  'CF-RAY': '62660fc6bcd3ed87-SJC',
  'Content-Type': 'text/plain;charset=UTF-8'
}
Error: Invalid credentials

@philosowaffle
Copy link

philosowaffle commented Feb 24, 2021

I think Garmin pushed a change this afternoon, I also started getting auth failures out of the blue.
Couple others with the same issue: philosowaffle/peloton-to-garmin#74

@wsherliker
Copy link

Yes, had intermittent issues for a few weeks and then from yesterday it failed every time. us patch applied and tested, still not working. Garmin must have 'done something'...

From looking at the data it is the session.get(URL_PROFILE) that is failing and showing cloudflare details i.e. garmin are using cloudflare so it is not getting to the API endpoint.

Had a quick google and looks like there is this:
https://pypi.org/project/cloudscraper/
which could be substituted for the requests import... maybe...

@wsherliker
Copy link

Actually it is the profile fetch after logging in that fails. If you comment out as below it works.
In the api.py file just comment out the lines below and it works... The URL_PROFILE is not a valid page anymore.

    # Check login
    #res = session.get(URL_PROFILE)
    #if not res.ok:
    #    raise Exception("Login check failed.")
    #garmin_user = res.json()
    #logger.info('Logged in as {}'.format(garmin_user['fullName']))

@La0
Copy link
Owner

La0 commented Feb 24, 2021

Thanks guys for the report and finding a solution !

I won't be able to make a patch today, so if one of you want to contribute a Pull Request, i'd gladly review it.

I think we can use https://connect.garmin.com/modern/currentuser-service/user/info as URL_PROFILE now. It should return a similar payload once connected, with the user's name. It's important to keep a safety check there, to ensure the user is really connected (and avoid just accepting dummy cookies from Garmin...)

@La0
Copy link
Owner

La0 commented Feb 24, 2021

I tried that URL, and it seems to work.

You can test that patch by doing:

pip install https://github.com/La0/garmin-uploader/archive/fix-22.zip

If that patch works for you, i'll merge it and make a new release of garmin-uploader

@wingnut144
Copy link

Ok, that seems to have fixed it. Thanks for the update :)

@flackdl
Copy link

flackdl commented Feb 24, 2021

Thanks. That fixed it for me. I'm using your library in my "iFit to Garmin" web app. https://github.com/flackdl/ifit-garmin-sync

@aurelg
Copy link

aurelg commented Feb 25, 2021

It works here too! Thanks a lot! 👍

@akramer115
Copy link
Author

akramer115 commented Feb 25, 2021 via email

@La0
Copy link
Owner

La0 commented Feb 27, 2021

Thanks for your help, I just released garmin-uploader 1.0.9 with this patch.

You can now upgrade your installations:

pip install garmin-uploader==1.0.9

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

Successfully merging a pull request may close this issue.