【发布时间】:2020-11-05 03:09:29
【问题描述】:
我正在尝试使用 python 将文件发送到谷歌驱动器,但我被卡在了身份验证部分。
当我运行下面的代码时,谷歌的网页正确打开,我可以选择我的帐户,它给了我祝贺消息:“身份验证流程已完成。”。
import os
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from requests.auth import HTTPBasicAuth
#Then we authenticate to google
print("debug-2")
g_login = GoogleAuth()
print("debug-1")
g_login.LocalWebserverAuth()
print("debug0")
drive = GoogleDrive(g_login)
#And we send the file
print("debug1")
with open("test.txt","r") as file:
print("debug2")
file_drive = drive.CreateFile({'title':os.path.basename(file.name) })
file_drive.SetContentString(file.read())
file1_drive.Upload()
print("debug3")
看起来不错,但在我的 shell 中,代码卡在“debug-1”,好像“LocalWebserverAuth()”从未工作过。此外,我的驱动器中仍然没有文件,因此上传确实无法正常工作,而不仅仅是“视觉卡住”。
当我让它自行结束时,我得到一个 python 错误:httplib.ResponseNotReady.
欢迎任何想法!
更新: 连接问题。我的是没有使用代理造成的。
【问题讨论】:
标签: python oauth-2.0 google-drive-api google-authentication pydrive