我想上传一个 docx 文件到谷歌驱动器,我已经为谷歌驱动器 API 设置了客户端 ID,并下载了生成的 client_secrets.json 文件,并将其添加到放置我的代码的同一目录中。我的 python 代码如下:
import os
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
# Try to load saved client credentials
gauth.LoadCredentialsFile("mycreds.txt")
if gauth.credentials is None:
# Authenticate if they're not there
gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
# Refresh them if expired
gauth.Refresh()
else:
# Initialize the saved creds
gauth.Authorize()
# Save the current credentials to a file
gauth.SaveCredentialsFile("mycreds.txt")
# gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
test = 'demo.docx'
with open(test, "r", encoding="Latin-1") as file:
fn = os.path.basename(file.name)
file_drive = drive.CreateFile({'demo.docx': os.path.basename(file.name)})
file_drive.SetContentString(file.read())
file_drive.Upload()
print('File upload successful!')
当代码运行gauth.LocalWebserverAuth()
时,它会在 Web 浏览器上打开 google 身份验证页面。完成后,它说,The authentication flow has completed.
并返回代码并抛出错误。
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1129)
python-BaseException
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(53条)