python - 上传文件[PYTHON]时如何解决“403身份验证范围不足”
问题描述
.json
每当我关闭程序时,我都会尝试将一些文件保存到我的谷歌驱动器中。但是,我收到此错误:
HttpError: <HttpError 403 when requesting https://www.googleapis.com/upload/drive/v3/files?fields=id&alt=json&uploadType=multipart returned "Insufficient Permission: Request had insufficient authentication scopes.">
我大约 30 分钟前开始使用这个模块,并且正在使用我在网站上找到的内容,所以它可能非常明显,但这是我的代码:
SCOPES = 'https://www.googleapis.com/auth/drive'
store = file.Storage('credentials.json')
creds = None
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
drive_service = build('drive', 'v3', credentials=creds)
# updating function
async def googledriveupdate(file):
file_metadata = {'name': file}
media = MediaFileUpload('{}'.format(file),
mimetype='application/json')
file = drive_service.files().create(body=file_metadata,
media_body=media,
fields='id').execute()
print('File ID: ' + file.get('id'))
这个想法是每当我关闭程序时,都会调用这个函数并且我的所有文件都会被更新。但是,我收到 403 错误并且似乎无法修复它。知道这里发生了什么吗?
解决方案
问题不是我的范围,而是我的泡菜文件。
如果您也遇到此问题,请尝试删除您的 pickle 文件,然后再次运行该程序- 这对我有用
推荐阅读
- python - 尝试用 '_______' 替换长度 > 3 的数组中的所有字符串
- windows - 如何实现自定义 shell 脚本来终止本地端口?
- reactjs - 带有 useState 子对象的文本输入
- c# - 字符串插值有什么意义?
- automation - 如何从网站下载 3000 个文件?
- python - 使用 * 读取 Python 参数时 Docker 容器 Linux 的奇怪行为
- python - python3中正确的文件夹结构
- java - Java中如何获取内存消耗信息
- docker - Azure Web App + Docker + Linux:必须指定服务器错误 Host.DestinationHostUrl
- reactjs - 使用 Yup 进行逗号分隔的电子邮件验证