Google Sheets API HttpError 500 and 503
<p>Edit: solved, the issue was on Google's side. Occurs when requesting a sheet which had diagrams that had invalid intervals in them. Reported bug to Google.</p>

<p>Note: This issue has persisted for more than 2 days. I had it previously but it was automatically resolved after waiting a day. It has since rearisen.</p>

<p>I am currently using the Google Sheets API through Google's python api client. The authentication is OAuth2.0 and I did not change anything significant in my codebase but all of the sudden I am getting 100% error ratio, and it seems like it should be on Google's end. I fear that I am banned from using the API indefinitely, is this the case? My guess is that when I launched the script and immediately cancelled it with ctrl+c because I wanted to run a new version of it caused some issues.</p>

<p>I tried creating another project and using its credentials to make the request and got the same error. Tried having my friend run the script authenticating through his google account and he receives the same error. The independent <a href="http://pastebin.com/PHgpRmHe" rel="nofollow">source code can be found here</a> </p>

<p>About the source code: The get_credentials() (and therefore the authentication) is entirely copied from Google's python quickstart script as seen here <a href="https://developers.google.com/sheets/quickstart/python" rel="nofollow">https://developers.google.com/sheets/quickstart/python</a>.</p>

<p>Tracebacks:</p>

<pre><code>Traceback (most recent call last):
  File "Google_sheets.py", line 164, in &lt;module&gt;
    ss=Spreadsheet(SPREADSHEET_ID)
  File "Google_sheets.py", line 83, in __init__
    spreadsheetId=self.ssId, includeGridData=True).execute()['sheets']}
  File "C:\Users\Larsson\AppData\Local\Programs\Python\Python35-32\lib\site-packages\oauth2client\util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "C:\Users\Larsson\AppData\Local\Programs\Python\Python35-32\lib\site-packages\googleapiclient\http.py", line 838, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: &lt;HttpError 500 when requesting https://sheets.googleapis.com/v4/spreadsheets/12YdppOoZUNZxhXvcY_cRgfXEfRnR_izlBsF8Sin3rw4?alt=json&amp;includeGridData=true returned "Internal error encountered."&gt;
</code></pre>

<p>After retrying shortly after, I get another error:</p>

<pre><code>Traceback (most recent call last):
  File "Google_sheets.py", line 164, in &lt;module&gt;
    ss=Spreadsheet(SPREADSHEET_ID)
  File "Google_sheets.py", line 83, in __init__
    spreadsheetId=self.ssId, includeGridData=True).execute()['sheets']}
  File "C:\Users\Larsson\AppData\Local\Programs\Python\Python35-32\lib\site-packages\oauth2client\util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "C:\Users\Larsson\AppData\Local\Programs\Python\Python35-32\lib\site-packages\googleapiclient\http.py", line 838, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: &lt;HttpError 503 when requesting https://sheets.googleapis.com/v4/spreadsheets/12YdppOoZUNZxhXvcY_cRgfXEfRnR_izlBsF8Sin3rw4?includeGridData=true&amp;alt=json returned "The service is currently unavailable."&gt;
</code></pre>

<p>As described in <a href="https://developers.google.com/analytics/devguides/reporting/core/v3/coreErrors#standard_errors" rel="nofollow">Standard Error Responses</a>, error codes #500 and #503 are errors associated with servers. Recommended action for this is not to retry the query more than once.</p>

<p>To handle these error codes:</p>

<blockquote>
  <p>A 500 or 503 error might result during heavy load or for larger more complex requests. For larger requests consider requesting data for a shorter time period. Also <strong>consider</strong> <a href="https://developers.google.com/analytics/devguides/reporting/core/v3/coreErrors#backoff" rel="nofollow"><strong>implementing exponential backoff</strong></a>.</p>
</blockquote>

<p>An exponential backoff may be a good strategy for handling those errors if a high volume of requests or heavy network traffic causes the server to return errors. </p>

<p>In addition to that, you should also check if your application is exceeding the <a href="https://developers.google.com/sheets/limits" rel="nofollow">usage limits</a>. If it does, it is possible that your application code should be optimized to make fewer requests. You may opt to request additional quota in the Google API Console under the Quotas tab of a project if needed.</p>

python google-spreadsheet google-api google-api-client google-sheets-api