-
Notifications
You must be signed in to change notification settings - Fork 949
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
Add property expiry in gspread client #1453
Conversation
Hi :) This seems good. It seems like something difficult to test(?) The issue #1169 asked for:
I do not see that here. Is it a new |
yes because it needs the OAuth authentication method to be tested 😢
I chose not to raise an exception as the expiry can be refreshed on the first API call. and it's easier if the user checks the expiry and chooses to raise when it happens. I'll try to catch the API error in case of expired token but it needs me to run a query, then wait for at least a week and try again. So far I did not managed to trigger some API error it just refreshes silently |
okay. It seems a simple enough change 👍. Not sure if it fixes #1169 though as they asked for an Exception to be thrown(?) |
true, I won't close the user issue, I will let the user choose if this is enough and then close the issue it solves the issue. |
auth works using a class that encapsulate the HTTP requests. It does that by doing authentication calls before the actual call we want to do sometimes or adds some token to the HTTP call without us knowing about it. Here the auth class can return the expiry of the given token, if it is expired then the user is expected to remove the file |
ok, so the user would be expected to do something like... if client.expiry > datetime.today():
# throw error! cannot do things properly!
# no error, continue
worksheet.update_acell("A1", "hi") If I have misunderstood, perhaps you could provide a pseudocode sample in which this attribute could be used helpfully? :) |
yes that's how it could be used. |
To be honest I check the expiry value and it seems 1h in the past, I tried to print the value with UTC timezone and still 1h in the past, so that means the expiry date provided is wrong as it's already past so I am wondering on how is this value accurate. I am now running a script that uses oauth, sends a request every hours I will check if the expiry value has changed. |
ok. seems a good change 👌 can merge |
actually after my last test, the script has been running for over a week and never expired. |
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. Signed-off-by: Alexandre Lavigne <[email protected]>
5c63b39
to
c884ff6
Compare
@alifeee I am ready to merge this PR, after checking the behavior, even if the credentials are expired, we can make requests and it still works anyway. and credentials get refreshed ! if anyone needs to know we can expose this property anyway even if it has a limited usage it does not break anything and provides information to the user. Waitting for you review. |
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.