gspread.exceptions.SpreadsheetNotFound [英] gspread.exceptions.SpreadsheetNotFound
问题描述
我正在编写python(ver 3)脚本以使用gspread访问google doc.
I am writing a python(ver 3) script to access google doc using gspread.
1) import gspread
2) from oauth2client.service_account import ServiceAccountCredentials
3) scope = ['https://spreadsheets.google.com/feeds']
4) credentials = ServiceAccountCredentials.from_json_keyfile_name(r'/path/to/jason/file/xxxxxx.json',scope)
5) gc = gspread.authorize(credentials)
6) wks = gc.open("test").sheet1
test 是一个 google工作表,它似乎已打开并可以正常阅读,但是如果我尝试从Office excel文件中读取,则会出现错误.这就是它们的原因.外观:
test is a google sheet which seems to be opened and read fine but if I try to read from a Office excel file it gives me error.here is what they look:
test和mtg所在的文件夹与我在json文件中收到的电子邮件共享.两个文件也与该电子邮件共享.
The folder which test and mtg are under is shared with the email I got in json file.Also both files were shared with that email.
尝试:
wks = gc.open("mtg.xls").sheet1
和
wks = gc.open("mtg.xls").<NameOfFirstSheet>
和
wks = gc.open("mtg").<NameOfFirstSheet>
错误:
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/gspread/client.py",152行,处于打开状态提高SpreadsheetNotFound gspread.exceptions.SpreadsheetNotFound
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/gspread/client.py", line 152, in open raise SpreadsheetNotFound gspread.exceptions.SpreadsheetNotFound
推荐答案
在文件名的末尾没有要添加的 .xls
,数据以其他格式保存(并且以后可以导出为 .xls
).
There is no .xls
to be added at the end of the file name, the data is saved in a different format (and can later be exported as .xls
).
尝试将您的代码分成:
ss = open("MTG_Collection_5_14_16")
ws = ss.worksheet("<NameOfFirstSheet>")
并发布错误消息(如果有).
and post the error message if any.
电子表格
实例具有属性 sheet1
,因为它是第一个工作表的默认名称. ss.sheet1
实际上返回具有索引0的工作表,而不管其名称是什么.
Spreadsheet
instances have an attribute sheet1
because it is the default name for the first worksheet. ss.sheet1
actually returns the worksheet with index 0, no matter what its name is.
如果要访问其他工作表,则需要使用 ss.worsheet(< title>")
或 ss.get_worksheet(< index>)中的一个
If you want to access another worksheet, you need to use one of ss.worsheet("<title>")
or ss.get_worksheet(<index>)
. ss.<NameOfFirstSheet>
will not work.
这篇关于gspread.exceptions.SpreadsheetNotFound的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!