8

I'm using aiohttp for a long-running process. At the beginning I authorize with the API get back an access token. The response also includes a refresh_token value (I think it's using oauth2).

The process I'm running takes over an hour and the access token expires after 60 minutes (as indicated by the expires_in value of 3600 in the auth response. I think I can refresh the authorization using the refresh_token but would ideally like to configure the client session to automatically refresh as needed.

I'm thinking that it should either:

  • Automatically refresh the tokens as soon as one of the responses returns a 401 code and then retry
  • Automatically refresh the token after a specified amount of time (e.g. 3500 seconds)

Is there a recommended way to subclass ClientSession for aiohttp. I found this one example but don't quite follow it.

Michael S.
  • 327
  • 1
  • 2
  • 11

0 Answers0