gpt4 book ai didi

python - 使用 API 将图像上传到 GDrive - Python

转载 作者:太空宇宙 更新时间:2023-11-03 19:11:49 24 4
gpt4 key购买 nike

我想将 aj 图像上传到 Google 云端硬盘。该图像与我上传图像的脚本位于同一目录中。我在 script.py 文件中有这段代码

#!/usr/bin/python

import httplib2
import pprint
from apiclient.discovery import build
from apiclient.http import MediaFileUpload
from oauth2client.client import OAuth2WebServerFlow

filename = 'image.jpg'
mimetype = 'image/jpg'

drive_service = build('drive', 'v2', developerKey='MY Simple API Access KEY')

# Insert a file
media_body = MediaFileUpload(filename, mimetype=mimetype, resumable=True)
body = {
'title': 'This is an image',
'description': 'This is a description',
'mimeType': mimetype
}

file = drive_service.files().insert(body=body, media_body=media_body).execute()

pprint.pprint(file)

运行python script.py时出现此错误:

Traceback (most recent call last):
File "script.py", line 22, in <module>
file = drive_service.files().insert(body=body, media_body=media_body).execute()
File "/usr/local/lib/python2.7/dist-packages/oauth2client/util.py", line 120, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/apiclient/http.py", line 656, in execute
_, body = self.next_chunk(http=http)
File "/usr/local/lib/python2.7/dist-packages/oauth2client/util.py", line 120, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/apiclient/http.py", line 733, in next_chunk
raise ResumableUploadError("Failed to retrieve starting URI.")
apiclient.errors.ResumableUploadError: Failed to retrieve starting URI.

最佳答案

您没有正确执行授权,请查看 Google Drive SDK 文档中的快速入门以获取分步说明:

https://developers.google.com/drive/quickstart

关于python - 使用 API 将图像上传到 GDrive - Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12727421/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com