通过python访问Google Spreadsheets数据

时间:2018-01-16 20:24:45

标签: python

我正在尝试将我的ipython(jupyter)脚本中的数据输出到谷歌电子表格中。

我按照说明here将此代码放入我的python脚本中:

我在oauth2client.service_account导入ServiceAccountCredentials的这一行继续收到错误。

这是错误:TypeError: init ()得到了一个意外的关键字参数' openType'

我尝试了以下但似乎没有任何效果。有什么建议?? pip安装pyopenSSL pip install pyasn1-modules pip install pyasn1 pip install --upgrade google-auth-oauthlib

1 个答案:

答案 0 :(得分:1)

我有同样的问题。这是我的代码(gspread模块的示例代码):

# use creds to create a client to interact with the Google Drive API
scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('secret.json', scope)
client = gspread.authorize(creds)

# Find a workbook by name and open the first sheet
# Make sure you use the right name here.
sheet = client.open("Book_name").sheet1

# Extract and print all of the values
list_of_hashes = sheet.get_all_records()
print(list_of_hashes)

解决方案是手动重新安装pyasn1 / pyasn1-modules软件包!

Try pip install pyasn1-modules -U or just reinstall pyasn1 / pyasn1-modules.

在此处找到:https://github.com/etingof/pyasn1-modules/issues/10#issuecomment-360922132