Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pydrive:尝试从远程服务器将文件上载到Google Drive_Python_Ubuntu_Google Drive Api_Google Oauth_Pydrive - Fatal编程技术网

Python pydrive:尝试从远程服务器将文件上载到Google Drive

Python pydrive:尝试从远程服务器将文件上载到Google Drive,python,ubuntu,google-drive-api,google-oauth,pydrive,Python,Ubuntu,Google Drive Api,Google Oauth,Pydrive,我正试图用一个python脚本从(Ubuntu)服务器远程上传文件到GoogleDrive 在我的代码中,Pydrive中有以下几行简单的代码: from pydrive.auth import GoogleAuth from pydrive.drive import GoogleDrive gauth = GoogleAuth() gauth.LocalWebserverAuth() drive = GoogleDrive(gauth) file = drive.CreateFile({"

我正试图用一个python脚本从(Ubuntu)服务器远程上传文件到GoogleDrive

在我的代码中,Pydrive中有以下几行简单的代码:

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)

file = drive.CreateFile({"parents": [{"kind": "<directory_name>","id": "<directory_id>"}]})
file.SetContentFile('<file_name>')
file.Upload()
从pydrive.auth导入GoogleAuth
从pydrive.drive导入GoogleDrive
gauth=GoogleAuth()
gauth.LocalWebserverAuth()
驱动器=谷歌驱动器(高斯)
file=drive.CreateFile({“parents”:[{“kind”:“”“id”:“”}]})
SetContentFile(“”)
file.Upload()文件
我在python目录中有一个setting.yaml文件,这样脚本可以在第一次手动身份验证后自动进行身份验证,还有一个client_secrets.json。我基本上遵循了所有的步骤

然而,当我在远程Ubuntu服务器上激活我的脚本时,我会连接到终端环境中的google页面,询问我的电子邮件地址和密码。当我输入这些信息时,谷歌要求进行第二次身份验证:要么查看带有代码的图像(终端上没有显示任何内容),要么“收听并键入您听到的号码”。当我输入该命令时,终端回复“未找到”,我听不到任何声音(见下图)

我陷入困境,不知道如何绕过这个问题。不幸的是,我需要至少进行一次身份验证,然后脚本将自动进行身份验证。我真的不知道如何跳过这一步

如有任何想法/意见/见解,将不胜感激

多谢各位
Berti

如文件中所述:

您还可以使用
CommandLineAuth()
,它在命令行手动从用户获取代码

LocalWebserverAuth()
将在localhost:8080上生成一个本地web服务器侦听(默认情况下),并尝试在用户的web浏览器上打开身份验证URL。身份验证后,打开的页面将把身份验证代码传递给本地主机上运行的本地服务器

这里的问题是,在远程服务器上运行此代码无法在本地计算机的浏览器中打开链接,因此无法登录

使用
CommandLineAuth()
将在远程服务器的终端上打印一个URL,您可以在本地浏览器中打开该URL。然后在浏览器中进行身份验证,这将为您提供身份验证代码,您需要从本地浏览器复制并粘贴到终端的提示中

从pydrive.auth导入GoogleAuth
从pydrive.drive导入GoogleDrive
gauth=GoogleAuth()

非常感谢你的回答。我完全按照你所说的修改了代码,它成功了。你成就了我的一天:)谢谢你提供的链接。当我尝试命令行身份验证时,我遇到了重定向uri的问题,它被设置为localhost://8080. 你是怎么解决的?