首页 > 解决方案 > 在 pycharm 中,当我尝试访问 googlesheet 时显示以下错误。请我的代码和错误

问题描述

from oauth2client.service_account import ServiceAccountCredentials

import gspread

scope = ['https://www.googleapis.com/auth/drive']

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

client = gspread.authorize(credentials)

worksheet = client.open("PM").sheet1

res = worksheet.get_all_records()

print(res)

错误

Traceback (most recent call last):

  File "F:\Arul Files\Python\EXE\main.py", line 10, in <module>

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

  File "F:\Arul Files\Python\venv\lib\site-packages\oauth2client\service_account.py", line 219, in from_json_keyfile_name

    with open(filename, 'r') as file_obj:
FileNotFoundError: [Errno 2] No such file or directory: 'key.json'

标签: pythonpython-3.x

解决方案


推荐阅读