gphotos-sync: InvalidGrantError: (invalid_grant) Token has been expired or revoked.
I have been running gphotos-sync on a nightly cron job, and it last succeeded 2021-01-11 at 1AM. Ever since, it has been failing with this issue (both with the snap version and the pip version; this error is from pip version 2.14.2):
01-16 20:54:54 WARNING gphotos-sync 2.14.2 2021-01-16 20:54:54.785955
01-16 20:54:54 ERROR
Process failed.
Traceback (most recent call last):
File "/home/ohad/.local/share/virtualenvs/photos-aX3072vj/lib/python3.8/site-packages/requests_oauthlib/oauth2_session.py", line 477, in request
url, headers, data = self._client.add_token(
File "/home/ohad/.local/share/virtualenvs/photos-aX3072vj/lib/python3.8/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 198, in add_token
raise TokenExpiredError()
oauthlib.oauth2.rfc6749.errors.TokenExpiredError: (token_expired)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ohad/.local/share/virtualenvs/photos-aX3072vj/lib/python3.8/site-packages/gphotos/Main.py", line 417, in main
self.setup(args, db_path)
File "/home/ohad/.local/share/virtualenvs/photos-aX3072vj/lib/python3.8/site-packages/gphotos/Main.py", line 309, in setup
self.google_photos_client = RestClient(photos_api_url, self.auth.session)
File "/home/ohad/.local/share/virtualenvs/photos-aX3072vj/lib/python3.8/site-packages/gphotos/restclient.py", line 38, in __init__
service_document = self.auth_session.get(api_url).json()
File "/home/ohad/.local/share/virtualenvs/photos-aX3072vj/lib/python3.8/site-packages/requests/sessions.py", line 555, in get
return self.request('GET', url, **kwargs)
File "/home/ohad/.local/share/virtualenvs/photos-aX3072vj/lib/python3.8/site-packages/requests_oauthlib/oauth2_session.py", line 496, in request
token = self.refresh_token(
File "/home/ohad/.local/share/virtualenvs/photos-aX3072vj/lib/python3.8/site-packages/requests_oauthlib/oauth2_session.py", line 446, in refresh_token
self.token = self._client.parse_request_body_response(r.text, scope=self.scope)
File "/home/ohad/.local/share/virtualenvs/photos-aX3072vj/lib/python3.8/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 421, in parse_request_body_response
self.token = parse_token_response(body, scope=scope)
File "/home/ohad/.local/share/virtualenvs/photos-aX3072vj/lib/python3.8/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 431, in parse_token_response
validate_token_parameters(params)
File "/home/ohad/.local/share/virtualenvs/photos-aX3072vj/lib/python3.8/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 438, in validate_token_parameters
raise_from_error(params.get('error'), params)
File "/home/ohad/.local/share/virtualenvs/photos-aX3072vj/lib/python3.8/site-packages/oauthlib/oauth2/rfc6749/errors.py", line 405, in raise_from_error
raise cls(**kwargs)
oauthlib.oauth2.rfc6749.errors.InvalidGrantError: (invalid_grant) Token has been expired or revoked.
01-16 20:54:54 WARNING Done.
I haven’t revoked the token nor does it have an expiry date. I’ve created a second oauth key, and using it I get the same result.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 20 (11 by maintainers)
I have found the solution for me. You have to ‘publish’ the app to allow functioning of repeat tokens. I’m now on week 3 without retrieving new token since publishing when it used to be 7 days. See newest readme info in latest git submission.
Sent from my mobile phone
On Wed, 30 Jun 2021, 18:25 Slavi Pantaleev, @.***> wrote:
Hi, occasionally the authorization token refresh fails and you will get his (its not the oauth secret key so recreating that does not help)
if you run gphotos sync with --new-token it will ask you for your login details again and fix the issue (–new-token is from memory and I cant check right now - use --help if I have got the option name wrong)
On Sat, 16 Jan 2021 at 21:07, Ohad Lutzky notifications@github.com wrote:
yep, the message is not mine but there may be an opportunity to trap that exception and make a better message. I’ll put it on the todo list.
On Sat, 16 Jan 2021 at 21:22, Ohad Lutzky notifications@github.com wrote: