python - 无法在不出现 404 错误的情况下更改 Google Sheets API 中的 SCOPES:未找到请求的实体
问题描述
每当我尝试运行该代码时都会收到此错误: HttpError 404 when requesting https://sheets.googleapis.com/v4/spreadsheets/1KpJw640oNNwVfEasGoSffrfoyC7i1ryHakdWZmr-AX4/values:batchUpdate?alt=json返回“未找到请求的实体。”>我正在尝试借助此 API 更新 Google Sheet 文件,但我管理使用的唯一范围是“只读”。我尝试删除 token.pickle 文件:我已被识别,因此该请求不需要身份验证凭据。但我不知道为什么我仍然会收到错误。所以基本上我能做的就是从工作表中提取数据而不是覆盖单元格。
from __future__ import print_function
from pprint import pprint
from googleapiclient import discovery
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'] #what I have changed from the Python Quickstart code from the Google Sheets API website
creds = None
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
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()
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
service = discovery.build('sheets', 'v4', credentials=creds)
spreadsheet_id = '1KpJw640oNNwVfEasGoSffrfoyC7i1ryHakdWZmr-AX4' #this id is correct and still I get an error
batch_update_values_request_body = {
'value_input_option': 'USER_ENTERED',
'data': [
{
"range": "Control Panel!A:B",
"majorDimension": "ROWS",
"values": [[1,2]]
}
],
}
request = service.spreadsheets().values().batchUpdate(spreadsheetId=spreadsheet_id,
body=batch_update_values_request_body)
response = request.execute()
pprint(response)
解决方案
推荐阅读
- sql - MSSQL 服务器中如何计算非聚集索引的 index_id?
- ms-access - 防止数据在 Access 表中更改
- mysql - 如何在 MYSQL 表中找到两个不同日期之间的数据,例如(29-05-2021 到 08-06-2021)
- java - 在 Apache Camel XML 中将 DOM 转换为 XML
- javascript - 如何使用 JavaScript 和 AJAX 根据邮政编码自动填充城市和州?
- forms - 使用 Java webstart 从带有参数的表单调用 Oracle 12c 报表
- kotlin - 使用协程实现后应用程序变慢
- python - 如何合并具有相同字段的数据框行?
- javascript - 如何将 json 数据从 ruby 控制器传递到 javascript (Rails 6.1)?
- python - 在python中查找丢失的坐标(纬度/经度)