繁体   English   中英

通过 Python 上传文件到 Google Drive

[英]Uploading file to Google Drive Via Python

参考: https://pythonhosted.org/PyDrive/步骤 1)https://pythonhosted.org/PyDrive/quickstart.html#authentication在本地 fs 工作目录中创建“client_secrets.json”。

from pydrive.auth import GoogleAuth
gauth = GoogleAuth()
gauth.LocalWebserverAuth()

错误:InvalidClientSecretsError Traceback(最近一次调用)/opt/conda/lib/python3.6/site-packages/pydrive/auth.py in LoadClientConfigFile(self, client_config_file) 385 try: --> 386 client_type, client_info = clientsecrets. loadfile(client_config_file) 387 除了 clientsecrets.InvalidClientSecretsError 作为错误:..... /opt/conda/lib/python3.6/site-packages/pydrive**/auth.py** 在 LoadClientConfigFile(self, client_config_file) 386 client_type , client_info = clientsecrets.loadfile(client_config_file) 387 except clientsecrets.InvalidClientSecretsError as error: --> 388 raise InvalidConfigError('Invalid client secrets file %s' % error) 389 如果不是 client_type in (clientsecrets.TYPE_WEB, 390 clientsecrets.TYPE_INSTALLED) :

InvalidConfigError:客户端机密文件无效,客户端类型“web”中缺少属性“redirect_uris”

尝试过

gauth = GoogleAuth()
credential_file = 'client_secrets.json' 
gauth.LoadCredentialsFile(credential_file)
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
gauth.SaveCredentialsFile(credential_file)

2 credential_file = 'client_secrets.json' #'../input/gdriveauth/client_secret_259511041847-no6nt8ennhbccaoqhv98ucsccv3hglu7.apps.googleusercontent.com.json' 3 #gauth.LoadCredentialsFile() 中的错误KeyError Traceback(最近调用最后一次) -> 4 gauth.LoadCredentialsFile(credential_file) ...

/opt/conda/lib/python3.6/site-packages/oauth2client/ client.py in new_from_json(cls, json_data) 300 # 找到并调用正确的类方法 from_json() 来恢复 301 # object. --> 302 module_name = data['_module'] 303 尝试:304 module_obj = import (module_name)

键错误:'_module'

您创建并下载了错误类型的凭据文件。

console.cloud.google.com创建凭据时,您需要选择“桌面”而非“Web”应用程序类型。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM