2

I want to reporting something to google spreadsheet, my code for example:

import json
import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope = ['https://spreadsheets.google.com/feeds']

credentials = ServiceAccountCredentials.from_json_keyfile_name('con.json', scope)

gc = gspread.authorize(credentials)


wks = gc.open("temperatura")

ws = wks.get_worksheet(0)



ws.update_acell('A1','IT WORKS!')

I get error:

gc = gspread.authorize(credentials) AttributeError: 'module' object has no attribute 'authorize'

Thanks for feedback

regards malin

malin
  • 21
  • 1
  • 4
  • 2
    Do you have a script named `gspread.py` in that directory? – PM 2Ring Nov 11 '17 at 09:39
  • No I don't have it ;/ – malin Nov 11 '17 at 09:56
  • 1
    Ok. That's a common cause of this kind of problem, but I suppose it's possible that there's another `gspread.py` somewhere in your Python path. You can check that you're getting the correct `gspread` by doing `print(gspread.__file__)`. That will show you the full file path to the module. Also, `print(dir(gspread))` will show you the main names connected to `gspread`. – PM 2Ring Nov 11 '17 at 10:00
  • I use command: sudo find / | grep gspread and result: /usr/local/lib/python2.7/dist-packages/gspread-0.1.0-py2.7.egg find: ‘/run/user/1000/gvfs’: Permission denied – malin Nov 11 '17 at 10:23
  • Sorry, I don't know what else to suggest. But hopefully the extra info you've posted will help someone who's familiar with `gspread` to solve your problem. – PM 2Ring Nov 11 '17 at 10:54
  • ServiceAccountCredentials this works. – halil Jan 29 '18 at 14:58

1 Answers1

0

Your code seems okay. Why don't you try installing gspread module again.

You can create a vitual environment in a folder and install all the required packages there.

This might help you run all your projects in a virtual environment without affecting other modules or packages.

$pip install virtualenv

$ cd my_project_folder $ virtualenv my_project

$cd my_project $source bin/activate

now you can install all your modules and packages.

http://docs.python-guide.org/en/latest/dev/virtualenvs/

  • I doit aand get the same error; AttributeError: 'module' object has no attribute 'authorize' – malin Nov 11 '17 at 10:40
  • After install virtualenv, I get new error: Traceback (most recent call last): File "test3.py", line 12, in wks = gc.open("temperatura").sheet1 File "/home/pi/.local/lib/python2.7/site-packages/gspread/client.py", line 89, in open raise SpreadsheetNotFound gspread.exceptions.SpreadsheetNotFound Traceback (most recent call last): File "test3.py", line 12, in wks = gc.open("temperatura").sheet1 File "/home/pi/.local/lib/python2.7/site-packages/gspread/client.py", line 89, in open raise SpreadsheetNotFound gspread.exceptions.SpreadsheetNotFound – malin Nov 11 '17 at 11:09
  • ok, this solve my problem, there you have to remember that Go to Google Sheets and share your spreadsheet with an email you have in your json_key['client_email']. Otherwise you’ll get a SpreadsheetNotFound exception when trying to open it. – malin Nov 11 '17 at 11:39