Instance of 'Resource' has no 'spreadsheets' member

Ouverte
#147 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
15/100
Type d'issue
Bug
Clarté
À clarifier
Activité
À l'abandon
Stack technique
python
Domaine
api

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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!

Langage dominant
Python
Étoiles
1.4k
Forks
917
Merge moyen
3 min
PR mergées (30 j)
1

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de googleworkspace/python-samples

Toutes les issues de googleworkspace/python-samples

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.