Pythoner Pythoner - 1 year ago 92
Python Question

EOL while scanning string liberal

I am relatively new to Python so please pardon my stupidity. I want to examine google sheet data and keep running into the EOL while scanning error. I have looked at other posts and tried various tactics but none seems to be fruition. I think Client email or the private id seems to be the problem with the quotes.

import gspread
from oauth2client.service_account import *

json_key = 'gspread-test.json'
scope = ['']

credentials = ServiceAccountCredentials.from_json_keyfile_name('', """
-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDVS4fuXzpnKrAI\nfaZEhkNdkcHKwcbQdYOhsxVwiaMkTffExvix+Uch37JaTIyCCw4D0CKv5bR\n5FOQPAVJgciJTUKK03UZJZfgtNWVY73dBq5DTL0afI2tn9+sKgtm/BulgA\nPrKtDmlp5YX7atgXbwJTjWpZ8OLOdBtwAcL0zBYS2PR/+qNOPT1NP1tJgTEMHmbN\nuyEl0Xqqrm87Ku7eaMEcmlQrhGLH2WmpR0YEXs2hQLGx\ne/RbqrD3qr/XYbRm9TwZkCyt\n-----END PRIVATE KEY-----\n
""", scope)

gc = gspread.authorize(credentials)

wks ='Simple data').sheet1

Answer Source

The function ServiceAccountCredentials.from_json_keyfile_name() takes 2 parameters:

  1. A path to a .json file which contains your client ID and client secret
  2. The scope url (which you have correct)

Something like this should work:

path_to_json = <<absolute path to json file>>
scope = ['']
credentials = ServiceAccountCredentials.from_json_keyfile_name(path_to_json, scope)
client = gspread.authorize(credentials)

Then client can be used to access whatever sheets you want.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download