chrisbillows / raindrop-todoist-syncer

Converts favourited Raindrops into tasks in Todoist.
2 stars 1 forks source link

Possible Error with Token Refresh #22

Open chrisbillows opened 7 months ago

chrisbillows commented 7 months ago

So I just ran with a stake token and the refresh logic triggered.

It got a token and added it correctly, however this error then triggered. The "test" of token freshness is an actual API call - collecting the first page of results. I thought this was at a lower level than the Tenacity check - but perhaps it's not and the Tenacity retries are triggered with the stale token which then fails?

(And please correct that damn logging statement you buffoon!! 😬😬😬😬)

2024-02-24 16:14:38 | INFO | Run started at 2024-02-24 16:14:38
2024-02-24 16:14:38 | INFO | Raindrop Client initalised
2024-02-24 16:14:38 | WARNING | Oauth token is stale.
2024-02-24 16:14:38 | INFO | Attempting to refresh token.
2024-02-24 16:14:39 | INFO | Your access token is <xxxxxxxxx>
2024-02-24 16:14:39 | INFO | Success! Oauth token refreshed. Oauth {oauth_token} written to .env.
2024-02-24 16:14:39 | INFO | Get all raindrops called
2024-02-24 16:14:42 | ERROR | RetryError[<Future at 0x105c3c8e0 state=finished raised HTTPError>]
Traceback (most recent call last):
  File "raindrop-todoist-syncer/venv/lib/python3.10/site-packages/tenacity/__init__.py", line 382, in __call__
    result = fn(*args, **kwargs)
  File "raindrop-todoist-syncer/raindrop.py", line 500, in _make_api_call
    response = self._core_api_call(page)
  File "raindrop-todoist-syncer/raindrop.py", line 477, in _core_api_call
    response.raise_for_status()
  File "raindrop-todoist-syncer/venv/lib/python3.10/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.raindrop.io/rest/v1/raindrops/0/?perpage=25&page=0

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "raindrop-todoist-syncer/main.py", line 93, in <module>
    main()
  File "raindrop-todoist-syncer/main.py", line 28, in main
    all_raindrops = raindrop_client.get_all_raindrops()
  File "raindrop-todoist-syncer/raindrop.py", line 441, in get_all_raindrops
    response = self._make_api_call(page)
  File "raindrop-todoist-syncer/venv/lib/python3.10/site-packages/tenacity/__init__.py", line 289, in wrapped_f
    return self(f, *args, **kw)
  File "raindrop-todoist-syncer/venv/lib/python3.10/site-packages/tenacity/__init__.py", line 379, in __call__
    do = self.iter(retry_state=retry_state)
  File "raindrop-todoist-syncer/venv/lib/python3.10/site-packages/tenacity/__init__.py", line 326, in iter
    raise retry_exc from fut.exception()
tenacity.RetryError: RetryError[<Future at 0x105c3c8e0 state=finished raised HTTPError>]