ringcentral / ringcentral-python

RingCentral Connect Platform Python SDK
MIT License
43 stars 35 forks source link

ApiException: Access token is expired / 401 error in long-running scripts #87

Open coldenol opened 1 week ago

coldenol commented 1 week ago

There is an issue in getting a 401 error (ApiException: Access token is expired) after 9-10 hours of script working.

This is the possible place of the issue: https://github.com/ringcentral/ringcentral-python/blob/a61e8739051b90de0e8585c0269d59029b9d0fb1/ringcentral/platform/auth.py#L120

My script is running for such a long intervals because of the API rate limits, and to download call recordings for a day it is running from 7 to 12 hours.

Unfortunately, I have no time to investigate the SDK and just trying to implement such a method in my RingCentralApi class that is being called before each API call:


    def _validate_token(self) -> None:
        """
        Checks if the token is about to expire within 60
        seconds. This is an additional layer of security to already
        existing token expiration checks in the RingCentral SDK.

        """
        expire_time = self.platform.auth().data().get("expire_time", 0)
        if expire_time <= time.time() + 60 or expire_time == 0:
            self.platform.refresh()

UPD: The workaround with the _validate_token() method didn't help. This time the script failed after 2 hours of running.

SDK version: ringcentral-0.9.0-py3-none-any.whl

denis-colomiets commented 1 week ago

So far my script has been running for 60 hours with no http issues. Still watching.