pe-st / garmin-connect-export

Download a copy of your Garmin Connect data, including stats and GPX tracks.
MIT License
376 stars 77 forks source link

Display name error, using Python 3 #65

Closed meek1 closed 2 years ago

meek1 commented 3 years ago

Tried: python gcexport.py --count all --username user_email_address

Got the following error related to "display name". Using Python 3.8.6.

Authenticating... Done. Getting display name...Traceback (most recent call last): File "gcexport.py", line 1255, in main(sys.argv) File "gcexport.py", line 1132, in main userstats_json = fetch_userstats(args.directory) File "gcexport.py", line 913, in fetch_userstats raise Exception('Did not find the display name in the profile page.') Exception: Did not find the display name in the profile page.

pe-st commented 3 years ago

Hello @meek1

Either you have no displayName (I don't suppose it) or the code that extracts it from some response file from Garmin doesn't like your displayName ;-) Here's how you can help me to find out...

Are you comfortable opening the file gcexport.py in an editor and making a small modification?

Around line 906 there is a line

    # write_to_file(args.directory + '/profile.html', profile_page, 'w')

Replace the line with (make sure that you don't keep the hash symbol from the original line)

    write_to_file(os.path.join(destination_dir, 'profile.html'), profile_page, 'w')

When you save your modifications and then run the script again, you should find a file profile.html in the export directory.

In my copy of this file there is somewhere the VIEWER_USERPREFERENCES, like that

window.VIEWER_USERPREFERENCES = JSON.parse("{\"displayName\":\"eschep\",\"preferredLocale\":

What does it look like in your profile.html file? Is there a displayName part in there? (You can send it to me by mail if you don't want to copy it here for everyone to see...)

pe-st commented 3 years ago

Hello @meek1

If this is still a problem, the new version 3.2.0 now saves you from editing the script to have the profile.html saved. Just start the script with the -v option

meek1 commented 3 years ago

Thanks @pe-st! Sorry for the slow response. Downloaded the latest version and tried same command as initially. Same result: "Exception: Did not find the display name in the profile page.".

The JSON.parse parts of the profile.html file include strings like: \"displayName\":\"user_email_address\", ...where user_email_address is my email address.

pe-st commented 3 years ago

Hello @meek1

I released a new version 3.2.1 that accepts email addresses as displayName. Can you try to see if it fixes your problem?

meek1 commented 3 years ago

Works now, thanks @pe-st!

Then I can start analyzing 10 years of training data... :)

wwwaliwalla commented 2 years ago

Hello @pe-st,

first of all thank you for the script, it has been working like a charm for several months. but since few daysI have exactly the same display name error with the script version 3.2.1 using python 3.8.10.

Tried with a fresh garmin account, fresh ubuntu machine, no way to make it work. Tried to log in using username or email address, Tried behing a fw, and even with direct internet access... always this error

login works fine, but always get "Did not find the display name in the profile page"

displayName is present in the profile.html file when using the -v option (as a name, not an email address, even if I use email address to log in). And other starnge thing is that even if I modify my display name in my account, as described here the display name recorded in the profile.html remains the same

therefore any help would be greatly appreciated

mainzelM commented 2 years ago

Same here, I get

Getting display name...Traceback (most recent call last):
  File "./gcexport.py", line 1299, in <module>
    main(sys.argv)
  File "./gcexport.py", line 1174, in main
    userstats_json = fetch_userstats(args)
  File "./gcexport.py", line 936, in fetch_userstats
    display_name = extract_display_name(profile_page)
  File "./gcexport.py", line 961, in extract_display_name
    raise Exception('Did not find the display name in the profile page.')
Exception: Did not find the display name in the profile page.

since a couple of days using version 3.2.1. I'm using an email address as username.

hannesweisbach commented 2 years ago

I have the same issue. Upon inspecting profile.html, I found that displayName now is a UUID:

"displayName":"f3ed1c7c-46a9-4315-8536-e145695c5fd2"

Edit: The problem seems to be the triple backslashs. The comment in code suggests that the format was

\"displayName\":\"John.Doe\"

at some point.

Just changing line 960 from

pattern = re.compile(r".*\\\"displayName\\\":\\\"(.+?)\\\".*", re.MULTILINE | re.DOTALL)

to

pattern = re.compile(r".*\"displayName\":\"(.+?)\".*", re.MULTILINE | re.DOTALL)

solves at least the issue with the Regex.

PS: I'm using python 3.9.9.

pe-st commented 2 years ago

Hello @wwwaliwalla, @mainzelM and @hannesweisbach, thank you for reporting this issue. I can confirm it.

It seems that Garmin changed the format of the profile.html that is returned. As you can see in the example file profile_simple.html, the quotes around the displayName used to be escaped with a backslash, hence the triple backslash in the regexp.

I think I should have some time in the coming days to fix this properly (changing also the unit test for the regexp); until then you can use the patch by @hannesweisbach as workaround.

As for the UUID used as displayName: it seems that this depends on the profile itself. My own profile still has my username as displayName, some user have an email address and now some users have a UUID...

pe-st commented 2 years ago

I integrated the patch from @hannesweisbach into the latest release 3.3.0, it fixes the issue for me. Feel free to reopen the issue if it still doesn't work at your end

mainzelM commented 2 years ago

@pe-st Thanks for the release, it works for me! Also thanks to @hannesweisbach for the quick fix.

LukeRabauke commented 2 years ago

Works again! Thank you and cheers from Stuttgart!!