Skip to content

Conversation

@LeagueOfPoro
Copy link

Adds a mechanism to proactively fetch a new Datadome cookie when a 403 Forbidden response is received from the TGTG API. This new method calls the Datadome SDK endpoint with a simulated device fingerprint to obtain a valid cookie, allowing the original request to be retried successfully.

Based on the following blog post: https://www.cereal-automation.com/blog/datadome-tgtg-api

Fixes #650, #631, #622, and related

Adds a mechanism to proactively fetch a new Datadome cookie when a 403 Forbidden response is received from the TGTG API. This new method calls the Datadome SDK endpoint with a simulated device fingerprint to obtain a valid cookie, allowing the original request to be retried successfully.
@sonar98
Copy link

sonar98 commented Nov 26, 2025

I tried your code. The code itself seems to run fine but I still get a 403 error.

[2025-11-26 15:19:22][tgtg][main.py:_print_welcome_message:289][INFO]
[2025-11-26 15:19:22][urllib3.connectionpool][connectionpool.py:_new_conn:1049][DEBUG] Starting new HTTPS connection (1): api.github.com:443
[2025-11-26 15:19:23][urllib3.connectionpool][connectionpool.py:_make_request:544][DEBUG] https://api.github.com:443 "GET /repos/Der-Henning/tgtg/releases/latest HTTP/1.1" 200 1471
[2025-11-26 15:19:23][tgtg][tgtg_client.py:login:345][INFO] Starting login process ...
[2025-11-26 15:19:23][urllib3.connectionpool][connectionpool.py:_new_conn:1049][DEBUG] Starting new HTTPS connection (1): apptoogoodtogo.com:443
[2025-11-26 15:19:24][urllib3.connectionpool][connectionpool.py:_make_request:544][DEBUG] https://apptoogoodtogo.com:443 "POST /api/auth/v5/authByEmail HTTP/1.1" 403 463
[2025-11-26 15:19:24][tgtg][tgtg_client.py:_post:246][WARNING] Received 403. Attempting to fetch a new Datadome cookie.
[2025-11-26 15:19:24][tgtg][tgtg_client.py:_get_datadome_cookie:192][INFO] Fetching new Datadome cookie...
[2025-11-26 15:19:24][urllib3.connectionpool][connectionpool.py:_new_conn:1049][DEBUG] Starting new HTTPS connection (1):
api-sdk.datadome.co:443
[2025-11-26 15:19:25][urllib3.connectionpool][connectionpool.py:_make_request:544][DEBUG] https://api-sdk.datadome.co:443 "POST /sdk/ HTTP/1.1" 200 238
[2025-11-26 15:19:25][tgtg][tgtg_client.py:_post:254][INFO] Retrying request with new Datadome cookie.
[2025-11-26 15:19:25][urllib3.connectionpool][connectionpool.py:_make_request:544][DEBUG] https://apptoogoodtogo.com:443 "POST /api/auth/v5/authByEmail HTTP/1.1" 403 463
[2025-11-26 15:19:25][tgtg][tgtg_client.py:_post:272][DEBUG] Datadome refresh did not solve the 403. Applying failsafe captcha logic.
[2025-11-26 15:19:26][urllib3.connectionpool][connectionpool.py:_make_request:544][DEBUG] https://apptoogoodtogo.com:443 "POST /api/auth/v5/authByEmail HTTP/1.1" 403 463
[2025-11-26 15:19:26][tgtg][tgtg_client.py:_post:246][WARNING] Received 403. Attempting to fetch a new Datadome cookie.
[2025-11-26 15:19:26][tgtg][tgtg_client.py:_get_datadome_cookie:192][INFO] Fetching new Datadome cookie...
[2025-11-26 15:19:26][urllib3.connectionpool][connectionpool.py:_new_conn:1049][DEBUG] Starting new HTTPS connection (1): api-sdk.datadome.co:443
[2025-11-26 15:19:27][urllib3.connectionpool][connectionpool.py:_make_request:544][DEBUG] https://api-sdk.datadome.co:443 "POST /sdk/ HTTP/1.1" 200 238
[2025-11-26 15:19:27][tgtg][tgtg_client.py:_post:254][INFO] Retrying request with new Datadome cookie.
[2025-11-26 15:19:27][urllib3.connectionpool][connectionpool.py:_make_request:544][DEBUG] https://apptoogoodtogo.com:443 "POST /api/auth/v5/authByEmail HTTP/1.1" 403 463

Refactor error handling and cookie management in tgtg_client.py. Simplify exception handling and improve cookie setting logic.
@LeagueOfPoro
Copy link
Author

Updated the code, try now?

@sonar98
Copy link

sonar98 commented Nov 26, 2025

Still the same error.

[2025-11-26 16:02:52][tgtg][main.py:_print_welcome_message:289][INFO]
[2025-11-26 16:02:52][urllib3.connectionpool][connectionpool.py:_new_conn:1049][DEBUG] Starting new HTTPS connection (1): api.github.com:443
[2025-11-26 16:02:52][urllib3.connectionpool][connectionpool.py:_make_request:544][DEBUG] https://api.github.com:443 "GET /repos/Der-Henning/tgtg/releases/latest HTTP/1.1" 200 1471
[2025-11-26 16:02:52][tgtg][tgtg_client.py:login:304][INFO] Starting login process ...
[2025-11-26 16:02:52][urllib3.connectionpool][connectionpool.py:_new_conn:1049][DEBUG] Starting new HTTPS connection (1): apptoogoodtogo.com:443
[2025-11-26 16:02:53][urllib3.connectionpool][connectionpool.py:_make_request:544][DEBUG] https://apptoogoodtogo.com:443 "POST /api/auth/v5/authByEmail HTTP/1.1" 403 463
[2025-11-26 16:02:53][tgtg][tgtg_client.py:_post:223][WARNING] Received 403. Attempting to fetch a new Datadome cookie.
[2025-11-26 16:02:53][tgtg][tgtg_client.py:_get_datadome_cookie:190][INFO] Fetching new Datadome cookie...
[2025-11-26 16:02:53][urllib3.connectionpool][connectionpool.py:_new_conn:1049][DEBUG] Starting new HTTPS connection (1): api-sdk.datadome.co:443
[2025-11-26 16:02:54][urllib3.connectionpool][connectionpool.py:_make_request:544][DEBUG] https://api-sdk.datadome.co:443 "POST /sdk/ HTTP/1.1" 200 238
[2025-11-26 16:02:54][tgtg][tgtg_client.py:_post:245][INFO] Retrying request with new Datadome cookie.
[2025-11-26 16:02:54][urllib3.connectionpool][connectionpool.py:_make_request:544][DEBUG] https://apptoogoodtogo.com:443 "POST /api/auth/v5/authByEmail HTTP/1.1" 403 463
[2025-11-26 16:02:54][tgtg][tgtg_client.py:_post:258][DEBUG] Datadome refresh did not solve the 403. Applying failsafe captcha logic.
[2025-11-26 16:02:55][urllib3.connectionpool][connectionpool.py:_make_request:544][DEBUG] https://apptoogoodtogo.com:443 "POST /api/auth/v5/authByEmail HTTP/1.1" 403 463
[2025-11-26 16:02:55][tgtg][tgtg_client.py:_post:223][WARNING] Received 403. Attempting to fetch a new Datadome cookie.

@LeagueOfPoro
Copy link
Author

@sonar98 Are you overriding the app version?

- TGTG_APK_VERSION=24.11.0

@Der-Henning
Copy link
Owner

Hi @LeagueOfPoro. Thank you for your contribution.
Please do not change code (i.e. formatting), that does not belong to your change and use ruff for formatting.
You can simply install pre-commit via poetry install and run make lint or pre-commit run -a.
Reformatting the whole file makes it difficult to see the actual code changes.

I will have a look at your contribution later and give you a more detailed review.

@sonar98
Copy link

sonar98 commented Nov 27, 2025

@sonar98 Are you overriding the app version?

- TGTG_APK_VERSION=24.11.0

Yes, I tried it with 24.11.0

@vincentkenny01
Copy link

I tried it too but getting similar errors.

@sonar98
Copy link

sonar98 commented Nov 27, 2025

I added some logging to see what is going on.

self.datadome_cookie -> shows a datadome_cookie, so this works.

I logged the variables in this response:
response = self.session.post(request_url, access_token=self.access_token, **kwargs)

request_url -> https://apptoogoodtogo.com/api/auth/v5/authByEmail
self.acces_token -> None

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 this pull request may close these issues.

Captcha error after updating the app

4 participants