ERROR: ('invalid_grant: Bad Request'

2,320 views
Skip to first unread message

Steve Gayner

unread,
Jul 7, 2020, 9:47:50 PM7/7/20
to Got Your Back: Gmail Backup
GYB Windows 10 version 1909
Haven't run GYB for over a year. Successful many times during that time frame. 
Used the command I always use to get mail by year. Got a failure.
Found updated version. Unzipped into existing directory.

Same failure:  
Command: e:\GMail GYB Backup>gyb --email xxxx...@gmail.com --search "before:2020 after:2018"  [where xxxx.yyyy is my valid gmail userid, used before for GYB]
Error:
ERROR: ('invalid_grant: Bad Request', '{\n  "error": "invalid_grant",\n  "error_description": "Bad Request"\n}')

I have no idea what to do. Tried searching for parts of that error message, but I usually wind up in a Python thread.

Any pointers? 

TIA.

Steve

Jay Lee

unread,
Jul 7, 2020, 9:52:28 PM7/7/20
to Got Your Back: Gmail Backup
Run

gyb --action revoke --email x...@gmail.com

this will revoke the old authorization (which was likely removed from your account when you reset your password or removed it). Then re-run your command, you'll be walked back through authorization and then it should work.

Jay Lee


--
--
You received this message because you are subscribed to the Google
Groups "Got Your Back: Gmail Backup" group.
To post to this group, send email to got-yo...@googlegroups.com
To unsubscribe from this group, send email to
got-your-bac...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/got-your-back?hl=en?hl=en

---
You received this message because you are subscribed to the Google Groups "Got Your Back: Gmail Backup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to got-your-bac...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/got-your-back/e2a337e3-e659-41a2-8347-a139b627025fo%40googlegroups.com.

Steve Gayner

unread,
Jul 7, 2020, 10:53:53 PM7/7/20
to Got Your Back: Gmail Backup
Thank you for your input. I tried that:
e:\GMail GYB Backup>gyb --action revoke --email xxxx...@gmail.com
results in:
ERROR: ('invalid_grant: Bad Request', '{\n  "error": "invalid_grant",\n  "error_description": "Bad Request"\n}')

Is there a manual way I can revoke?

Brett Carver

unread,
Jul 15, 2020, 3:25:35 AM7/15/20
to Got Your Back: Gmail Backup
I started getting this problem yesterday.  I have 4 accounts I'm backing up.

1.  G Suite legacy - works fine

2.  Gmail
ERROR: ('invalid_grant: Bad Request', '{\n  "error": "invalid_grant",\n  "error_description": "Bad Request"\n}')

3, and 4.  Gmail
ERROR: ('invalid_grant: Token has been expired or revoked.', '{\n  "error": "invalid_grant",\n  "error_description": "Token has been expired or revoked."\n}')

Doing the --action revoke has no effect and generates the same errors as above.

Jay Lee

unread,
Jul 15, 2020, 6:13:59 AM7/15/20
to Got Your Back: Gmail Backup
You can just delete the .cfg file named after the email address and then reauth.

Jay

--
--
You received this message because you are subscribed to the Google
Groups "Got Your Back: Gmail Backup" group.
To post to this group, send email to got-yo...@googlegroups.com
To unsubscribe from this group, send email to
got-your-bac...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/got-your-back?hl=en?hl=en

---
You received this message because you are subscribed to the Google Groups "Got Your Back: Gmail Backup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to got-your-bac...@googlegroups.com.

E

unread,
Jul 15, 2020, 7:03:29 AM7/15/20
to Got Your Back: Gmail Backup
Same issue started about 3am UTZ this morning here.

ERROR: ('invalid_grant: Token has been expired or revoked.', '{\n  "error":
        "invalid_grant",\n  "error_description": "Token has been expired or revoke
       d."\n}')

Brett Carver

unread,
Jul 15, 2020, 9:44:37 PM7/15/20
to got-yo...@googlegroups.com
You can just delete the .cfg file named after the email address and then reauth.

That worked.  I bit of a PitA - lots of clicking and copy/pasting.   I hope whatever happened to break all the accounts doesn't happen often.

E

unread,
Jul 16, 2020, 5:36:51 AM7/16/20
to Got Your Back: Gmail Backup
Same

Steve Adeff

unread,
Sep 4, 2020, 1:06:54 PM9/4/20
to Got Your Back: Gmail Backup
I'm having this issue too, but not sure where this .cfg file is, I have two sqlite files.

Matthew Lancey

unread,
May 25, 2021, 3:34:01 AM5/25/21
to Got Your Back: Gmail Backup
Found this conversation via a Google search for the "bad request" error, which I started seeing a few days ago. This reply is aimed at anyone else who arrives here for the same reason!

  1. The .cfg file, for me, was in the same folder that I run gyb from. Having said that, I'm on a Mac, so Windows users might have a different experience
  2. The resolution for the problem was indeed to just remove the .cfg file - actually I just changed the extension to .cfg.bak instead - and re-running the gyb command I usually run for an incremental backup.
In doing this I expected to have to go through the full long-winded (re-)auth process with Google, but actually all I needed to do was paste the first short link gyb provided; re-authenticate my Google account in the browser; then copy/paste the verification code provided by Google back into gyb. After that, gyb launched straight into its usual process for syncing my email. Easy!




Simon Crosland

unread,
Jun 23, 2021, 4:51:46 AM6/23/21
to Got Your Back: Gmail Backup
I am now seeing this error every 7 days and to recover I have to delete the .cfg file and go through the quick re-authentication process described in the previous message.

I am using gyb with a consumer @gmail account and a Google Workspace domain. The @gmail.com account is used as the service account for the Google Workspace domain so that I only have to have one installation of gyb. 

The error occurs when running gyb to back up the @gmail.com account, but never affects the Google Workspace even after the @gmail.com account is in the error state and will not itself complete a backup. When the error happens gyb exits with status 18.

A redacted snippet from my logging:

/Users/***/bin/gyb/gyb --email "***@gmail.com" --local-folder "/Volumes/Data One/Backups/Gmail/***" --action backup
ERROR: ('invalid_grant: Token has been expired or revoked.', {'error': 'invalid_grant', 'error_description': 'Token has been expired or revoked.'})
Return code: 18
Stdout: None
Stderr: None

I'd be happy to try to help debug this problem. I'm wondering if I'll have to end up with two gyb installations, one for the @gmail.com account and one for the Google Workspace domain?

Cheers,
Simon

Tony Scelfo

unread,
Jun 23, 2021, 5:56:16 PM6/23/21
to got-yo...@googlegroups.com
I also get the "ERROR: ('invalid_grant: Token has been expired or revoked.', {'error': 'invalid_grant', 'error_description': 'Token has been expired or revoked.'})" errors often. Deleting the .cfg and re-authenticating fixes everything for about a week until it fails again. I don't fix it every time it happens so I can't confirm the same 7 day pattern but that seems about right based on the times I have gone to reauthenticate.

--
--
You received this message because you are subscribed to the Google
Groups "Got Your Back: Gmail Backup" group.
To post to this group, send email to got-yo...@googlegroups.com
To unsubscribe from this group, send email to
got-your-bac...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/got-your-back?hl=en?hl=en

---
You received this message because you are subscribed to the Google Groups "Got Your Back: Gmail Backup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to got-your-bac...@googlegroups.com.

Ketan Vijayvargiya

unread,
Apr 30, 2022, 4:57:32 PM4/30/22
to Got Your Back: Gmail Backup
I started using GYB and am running into the same problem: "I am now seeing this error every 7 days and to recover I have to delete the .cfg file and go through the quick re-authentication process described in the previous message."

I use a regular/consumer Gmail address, not related to Google Workspace.

I setup a daily cron to backup my Gmail account and it stopped working after a week.

Any ideas on how I can fix this in a permanent way?

Jay Lee

unread,
Apr 30, 2022, 4:59:22 PM4/30/22
to Got Your Back: Gmail Backup
This is unfortunately expected behavior. Google revoked the token on projects in "test" mode every 7 days. I'm not aware of a workaround for consumer accounts.

Jay

Dylan Gordon

unread,
Sep 8, 2022, 7:31:44 AM9/8/22
to Got Your Back: Gmail Backup
This is getting beyond my expertise, but is it possible using another OAuth flow might work? The gmvault people are talking about migrating to the loopback flow. See:

and


Dylan

Dylan Gordon

unread,
Sep 8, 2022, 7:36:23 AM9/8/22
to Got Your Back: Gmail Backup
Just saw this:

"It seems that there is a way to circumvent the 7 days expiration for the refresh token. You have to publish the application and then skip sending any verification details. Just clicking the publish button and creating a new refresh token is enough (sometimes you need to recreate again after 7 days in order for it to work)."
https://github.com/guillaumeaubert/gmvault-docker/issues/2#issuecomment-938706222

When I hit publish on my GYB app it told me I don't even need to send verification details so we'll see if this works..

Dylan

Jay Lee

unread,
Sep 8, 2022, 7:37:41 AM9/8/22
to Got Your Back: Gmail Backup
GYB is already using the loopback flow as of the March 1.60 release. The 7 day token revoke issue is a separate behavior of unpublished projects.

Jay

Dylan Gordon

unread,
Sep 17, 2022, 2:43:36 PM9/17/22
to Got Your Back: Gmail Backup
Well, the refresh token created after publishing the application is still valid 9 days later.

Can anyone tell me what the risks of having this be a public external app in my non-Workspace account are? 

If nothing dire, I might suggest editing https://github.com/GAM-team/got-your-back/wiki#general under "Important note:" to suggest publishing the project vs. having it read "you probably want to avoid that option" as it does right now.

Either way, probably still worth letting people know in this section that their refresh token will expire in 7 days. My own bad for not testing before now but I went a solid year+ assuming this was working when it worked for less than a week!
Reply all
Reply to author
Forward
0 new messages