petergardfjall / garminexport

Garmin Connect activity exporter and backup tool
Apache License 2.0
500 stars 85 forks source link

Fake useragent #77

Closed random1781 closed 3 years ago

random1781 commented 3 years ago

Added a user-agent generator in response to Garmin blocking requests from the default python-requests user-agent.

micky-gee commented 3 years ago

Tested and works. Thanks.

petergardfjall commented 3 years ago

Thanks for the supplied patch, however I'd prefer not to introduce extra dependencies nor network roundtrips in garminexport. I've created a fix in 33b83548675823f8f872a491363dffc9ba091992 which I still hope addresses the issue for both cli and library users.

CLI

A custom User-Agent can now be supplied via --user-agent.

garmin-backup --user-agent='Mozilla/5.0 (X11; Ubuntu; Linux i686 on x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2811.59 Safari/537.36'

If you prefer to rotate user agent, use a tool such as user_agent:

# installs the ua cli tool
pip install --user user_agent

garmin-backup --user-agent=$(ua)

Library

For library clients, one can pass a user_agent_fn function that, when called, produces a User-Agent string to be used as User-Agent for the remainder of the session.

micky-gee commented 3 years ago

Just a quick one:

however I'd prefer not to introduce extra dependencies nor network roundtrips

What is the extra network roundtrip introduced by this PR?

petergardfjall commented 3 years ago

Just a quick one:

however I'd prefer not to introduce extra dependencies nor network roundtrips

What is the extra network roundtrip introduced by this PR?

fake-useragent gets its data from Internet sites.

grabs up to date useragent from useragentstring.com randomize with real world statistic via w3schools.com