Instance of 'Resource' has no 'spreadsheets' member

未关闭
#147 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
15/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
python
领域
api

调研方向

The failing sample is the Google Sheets quickstart script (GSpread.py), and the traceback shows an ImportError for googleapiclient.discovery, so the first check is whether the interpreter VSCode runs has that package installed. The 'Resource has no spreadsheets member' message looks like an editor lint warning rather than a runtime failure. The issue has no linked fix and no agreed change, so it needs a maintainer decision on whether it is a sample bug or an environment question before any edit.

由索引模型根据 Issue 内容生成。

描述

I'm running Quickstart for Google Sheets APIv4 in VSCode and got the following error:
Instance of 'Resource' has no 'spreadsheets' member

and the following output:

[Running] python -u "./GSpread.py"
Traceback (most recent call last):
  File "./GSpread.py", line 4, in <module>
    from googleapiclient.discovery import build
ImportError: No module named googleapiclient.discovery
[Done] exited with code=1 in 0.092 seconds

Code (Quickstart for Google Sheets APIv4):

from __future__ import print_function
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly']
SAMPLE_SPREADSHEET_ID = '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms'
SAMPLE_RANGE_NAME = 'Class Data!A2:E'

def main():
    creds = None
    if os.path.exists('token.pickle'):
        with open('token.pickle', 'rb') as token:
            creds = pickle.load(token)
    # If there are no (valid) credentials available, let the user log in.
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)
        with open('token.pickle', 'wb') as token:
            pickle.dump(creds, token)

    service = build('sheets', 'v4', credentials=creds)

    sheet = service.spreadsheets()
    result = sheet.values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID,
                                range=SAMPLE_RANGE_NAME).execute()
    values = result.get('values', [])

    if not values:
        print('No data found.')
    else:
        print('Name, Major:')
        for row in values:
            print('%s, %s' % (row[0], row[4]))

if __name__ == '__main__':
    main()

Tried uninstalling/reinstalling/updating with:
pip3 install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib

Environment:

  • VSCode version (1.42.1)
  • Python version (3.81)
  • OS (Mac)

Thanks!

主要语言
Python
星标
1.4k
派生
917
平均合并
3 分钟
30 天内合并 PR
1

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

googleworkspace/python-samples 的其他 Issue

查看 googleworkspace/python-samples 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。