gspread: HTTP errors - intermittent

I’m getting intermittent HTTP errors when reading or (more frequently) writing to sheets. I moved to Gspread from GoogleCL, and I’ve been happy with ease and speed, but now I’m getting more of these errors. It works most of the time, but not consistently. Thanks in advance!

My code for writing is (essentially) here:

def SaveHistory(History, reassesslist, todaydict, date,did):
    username = '...'
    password = '...'
    sheetname = "Re"

    client = gspread.login(username, password)
    spreadsheet = client.open(sheetname)

    worksheet = spreadsheet.sheet1
    worksheet.resize(rows=1,cols=12)

    for row in reassesslist:
        worksheet.append_row(temp)    

The error (or at least the most recent one that I’ve gotten): Exception in Tkinter callback Traceback (most recent call last): File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gspread/client.py”, line 137, in open feed = self.get_spreadsheets_feed() File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gspread/client.py”, line 223, in get_spreadsheets_feed r = self.session.get(url) File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gspread/httpsession.py”, line 79, in get return self.request(‘GET’, url, **kwargs) File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gspread/httpsession.py”, line 75, in request raise HTTPError(response) HTTPError

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 32 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Yeah, this part of the ref needs more details.

You need to go to Google Developers Console. Create a new project (or select the one you have.)

credentials-page

Under “API & auth”, in the API enable “Drive API”.

enabled-apis

Go to “Credentials” and hit “Create new Client ID”.

Create Client ID

Select “Service account”. Hitting “Create Client ID” will generate a new Public/Private key pair. You will automatically download a JSON file with this data.

download-credentials

This is how this file looks like:

{
  "private_key_id": "2cd … ba4",
  "private_key": "-----BEGIN PRIVATE KEY-----\nNrDyLw … jINQh/9\n-----END PRIVATE KEY-----\n",
  "client_email": "473 … hd@developer.gserviceaccount.com",
  "client_id": "473 … hd.apps.googleusercontent.com",
  "type": "service_account"
}

You need client_email and private_key (yes, that’s a SIGNED_KEY)

Now you can read this file, and use the data when constructing your credentials:

import json
import gspread
from oauth2client.client import SignedJwtAssertionCredentials

json_key = json.load(open('gspread-april-2cd … ba4.json'))
scope = ['https://spreadsheets.google.com/feeds']

credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope)
gc = gspread.authorize(credentials)

Don’t forget to share your spreadsheet with an email you have in your json_key['client_email'].