-
Notifications
You must be signed in to change notification settings - Fork 948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Specific exception in case an authorization has expired #1169
Comments
Hi I had a look at the We could add some feature that returns the expiry, raise some exception when it has expired (by checking the return code etc). I might make it fit for the next release, not 100% sure though. |
In gspread client add a new property expiry which returns the expiry datetime object from the used credentials. The expiry only exists for OAuth credentials otherwise it returns None. closes #1169 Signed-off-by: Alexandre Lavigne <[email protected]>
@fredericomattos I added the extra property it returns the expiry for the current oauth credentials. I tried to run some code with a few days between each run and every time I open a sheet, the token is being refreshed and the expiry time changes. from there you can use this property to check the datetime and raise your Exception as you need. Hope it solves your issue. |
Hi @fredericomattos I ran some tests after many weeks. I noticed the following behavior:
I will go ahead with the PR exposing if the credentials are expired but I think its usage is limited. Just to let you know. |
In order not to need to create a new authorization each time I need it (sometimes I use it 8 times per code loop), I create a global object:
The problem with this is that authorization has an expiration time, which we find in
client_gspread.auth.expiry
It would be interesting if there was a single exception that handled the case of expired authorization, to be used directly when you need to update the authorization.
In the documentation in the area explaining how to authorization, it would be nice to also add how long an authorization lasts, so that new users can already create their projects knowing the time limitations of authorizations (putting the path to find the
expiry
time in the object created in the authorization, so there are no doubts betweentimeout
orexpiry
). Oh sure, it would also be nice to add to the documentation the answer to the question "if I perform a real action using gspread, is the authorization expiration time updated or fixed?"Because when the authorization is created, when analyzing its
vars
, we find thetimeout
attribute, which has no value, so the person may mistakenly understand that there is no expiration date.The text was updated successfully, but these errors were encountered: