googlesheetsapi与python。拒绝找到大多数模块,即使它们存在

2024-04-25 20:40:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经尝试了所有我能在互联网上找到的东西。我当前得到的错误是 “没有名为‘google_auth_oauthlib’的模块”,但当我查找该模块时,它说它存在。 我还尝试过运行quickstart.py,Google要求您运行,但我得到了错误“ModuleNotFoundError:没有名为“GoogleAppClient”的模块” 我再次寻找它,它确实存在。我试图运行的代码是

import os
from Google import Create_Service
 
CLIENT_SECRET_FILE = ('client_secret.json')
API_SERVICE_NAME = 'sheets'
API_VERSION = 'v4'
SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
 
service = Create_Service(CLIENT_SECRET_FILE, API_SERVICE_NAME, API_VERSION, SCOPES)

Tags: 模块nameimportclientauthapisecretversion
1条回答
网友
1楼 · 发布于 2024-04-25 20:40:04

我们面临同样的问题。我所做的:

pip install  upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib oauth2client

然后:

from googleapiclient.discovery import build
from google.oauth2 import service_account

file_id = "file_id"
creds = ServiceAccountCredentials.from_json_keyfile_name("json-file.json", scope)

drive_service = build("drive", "v3", credentials=creds)

request = drive_service.files().get_media(fileId=file_id)

这就成功了

相关问题 更多 >

    热门问题