I'm setting this up to purge infected or phishing emails that are bulk-sent to our users. I have a script that runs the purge command using my service account, pulling the necessary variables from a CSV. The issue is that it works fine if the CSV is small (lets say, 5 infected users, and thus 5 lines). But as soon as it starts getting bigger, it randomly throws errors for more than half for "invalid _grant" and "unauthorized_client". Do I have something misconfigured?
!/bin/bash
INPUT=/home/chris/Desktop/currentversion.csv
cd ~/gyb
OLDIFS=$IFS
IFS=,
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read -r MessageID Recipientaddress
do
python gyb.py --service-account [email protected] --search "rfc822msgid:$MessageID" --action purge --email $Recipientaddress
done < $INPUT
IFS=$OLDIFS
Traceback (most recent call last):
File "gyb.py", line 1323, in
main(sys.argv[1:])
File "gyb.py", line 575, in main
imapconn = gimaplib.ImapConnect(generateXOAuthString(options.email, options.service_account), options.debug)
File "gyb.py", line 269, in generateXOAuthString
service = apiclient.discovery.build('oauth2', 'v2', http=http)
File "/home/chris/gyb/oauth2client/util.py", line 128, in positional_wrapper
return wrapped(_args, *_kwargs)
File "/home/chris/gyb/apiclient/discovery.py", line 192, in build
resp, content = http.request(requested_url)
File "/home/chris/gyb/oauth2client/util.py", line 128, in positional_wrapper
return wrapped(_args, *_kwargs)
File "/home/chris/gyb/oauth2client/client.py", line 475, in new_request
self._refresh(request_orig)
File "/home/chris/gyb/oauth2client/client.py", line 653, in _refresh
self._do_refresh_request(http_request)
File "/home/chris/gyb/oauth2client/client.py", line 710, in _do_refresh_request
raise AccessTokenRefreshError(error_msg)
oauth2client.client.AccessTokenRefreshError: unauthorized_client
Traceback (most recent call last):
File "gyb.py", line 1323, in
main(sys.argv[1:])
File "gyb.py", line 575, in main
imapconn = gimaplib.ImapConnect(generateXOAuthString(options.email, options.service_account), options.debug)
File "gyb.py", line 269, in generateXOAuthString
service = apiclient.discovery.build('oauth2', 'v2', http=http)
File "/home/chris/gyb/oauth2client/util.py", line 128, in positional_wrapper
return wrapped(_args, *_kwargs)
File "/home/chris/gyb/apiclient/discovery.py", line 192, in build
resp, content = http.request(requested_url)
File "/home/chris/gyb/oauth2client/util.py", line 128, in positional_wrapper
return wrapped(_args, *_kwargs)
File "/home/chris/gyb/oauth2client/client.py", line 475, in new_request
self._refresh(request_orig)
File "/home/chris/gyb/oauth2client/client.py", line 653, in _refresh
self._do_refresh_request(http_request)
File "/home/chris/gyb/oauth2client/client.py", line 710, in _do_refresh_request
raise AccessTokenRefreshError(error_msg)
oauth2client.client.AccessTokenRefreshError: invalid_grant