0

I'm trying to use the gdata.spreadsheets.client and OAuth2TokenFromCredentials to process a google spreadsheet.
After 1 hour I receive a 401 error(unauthorized) due to access token expiration any way automatically refreshing the access token, though it's changing the new access token the process is frequently getting HTTP 401 error (unauthorized).

After reaching same error 10 times the process quits, so the file is not processed completely.

Sample code where we receive the 401 error:

def write_row(self, row, data_row):
    # Attempt to write new row and skip if writing row causes error.
    try:
        gdoc_util.update_row_retryable(self.spr_client, row, data_row, force=True)
    except Exception as e:
        logging.exception(e)
        self.writing_error_count += 1
        if self.writing_error_count > self.MAX_ERROR_COUNT:
            print 'Max error limit reached, ending scraper...'
            quit()

I am running this process with multiprocessing.

Why with new access tokens is not working like as before, but frequently receiving 401 error(unauthorized)?

Same error like here: Google Drive Python API resumable upload error 401 after 2 hours

Community
  • 1
  • 1
  • I am assuming that a single processing request itself isn't taking longer than an hour? If it is being done in smaller batches then I have a workaround that I have found helpful. But you will still be unauthorised for a split second each hour. – roganjosh Feb 04 '16 at 15:15
  • Hi, 1 hour is exactly to access token expiry time. Did you put the refresh token in your credentials? If yes, ouath2client would automatically get a new access token and then nothing should break. – DevLounge Mar 14 '16 at 19:37

0 Answers0