简体   繁体   English

尝试使用python访问“google drive”时出错(google quickstart.py源代码)

[英]Error trying to access “google drive” with python (google quickstart.py source code)

I'm trying to learn how to access Google Drive from Python but I have problems. 我正在尝试学习如何从Python访问Google云端硬盘,但我遇到了问题。

I followed the tutorial of google's official website: https://developers.google.com/drive/...t-python?hl=es In addition, i have seen the video tutorial about this, I think I do the same than the video guys exactly. 我按照谷歌官方网站的教程: https//developers.google.com/drive /... t-python?hl = es另外,我已经看过关于这个的视频教程,我想我做的比视频家伙。

I tell you the steps I've followed literally: 我告诉你我按照字面意思执行的步骤:

1 - Install pip tool to install the SDK from Google. 1 - 安装pip工具以从Google安装SDK。

2 - Install the SDK from Google: "pip install --upgrade google-api-python-client" 2 - 从Google安装SDK:“pip install --upgrade google-api-python-client”

In this step all goes well, in fact to make imports etc. there is no fault. 在这一步一切顺利,事实上,使进口等没有错。

3 - Drive Enable API: I follow the steps as is, create a "client ID for native application" and a "client ID for web application " 3 - Drive Enable API:我按照原样执行步骤,创建“本机应用程序的客户端ID”和“Web应用程序的客户端ID”

4 - I create the document "document.txt" and copy the source code as it quickstart. 4 - 我创建文档“document.txt”并快速启动时复制源代码。

5 - I replace "CLIENT_ID" and "CLIENT_SECRET" by appearing in "Client id for native application" (I've also tested with web application) 5 - 我通过出现在“本机应用程序的客户端ID”中替换“CLIENT_ID”和“CLIENT_SECRET”(我还使用Web应用程序进行了测试)

6 - I run, and screen output is: 6 - 我跑,屏幕输出是:

No handlers could be found for logger "oauth2client.util"
Go to the following link in your browser:
<link>
Enter verification code:

Looking for a solution, i found something to get some information about that error: 寻找解决方案,我发现了一些有关该错误的信息:

import logging
...
logging.basicConfig()

Now, the output is: 现在,输出是:

C:\workspaces\asd\prsGoogleApi>quickstart.py
WARNING:oauth2client.util:__init__() takes at most 4 positional arguments (5 giv
en)
Go to the following link in your browser:
<link>
Enter verification code:

If I try to access that link, the error is: 如果我尝试访问该链接,则错误为:

401 - That's an error
Error: invalid_client.
No application name.

Request details:
response_type=code
scope=https://www.googleapis.com/auth/drive
access_type=offline
redirect_uri=urn:ietf:wg:oauth:2.0:oob
client_id=...

The module in question oauthclient.util makes some assumptions that there is logging established and this warning is actually masking a more detailed warning/error which it tried to write to the log. 有问题的模块oauthclient.util做了一些假设,即建立了日志记录,这个警告实际上掩盖了它试图写入日志的更详细的警告/错误。

If you add some logging to your own code then it should reveal the underlying error: 如果您向自己的代码添加一些日志记录,那么它应该揭示底层错误:

import logging
logging.basicConfig()

was enough to replace the appearance of the above error with the true error in my output (YMMV). 足以用输出中的真实错误(YMMV)替换上述错误的外观。

Once that's resolved you can probably remove these two lines safely (although you'll probably wind up back here should something else go wrong). 一旦解决了这个问题,你可以安全地删除这两行(尽管如果出现其他问题,你可能会回到这里)。

This question came up in a google search for No handlers could be found for logger "oauth2client.util" alongside this issue and this issue . 谷歌搜索中出现了这个问题No handlers could be found for logger "oauth2client.util" 此问题此问题, No handlers could be found for logger "oauth2client.util"

I have found the problem, it was that I had not put my email address and client name at "Consent screen" section. 我发现了问题,就是我没有把我的电子邮件地址和客户名称放在“同意屏幕”部分。

Now it works good. 现在它运作良好。

Actually adding the code mentioned above fixes the problem entirely. 实际上添加上面提到的代码完全解决了这个问题。

import logging
logging.basicConfig(filename='debug.log',level=logging.DEBUG)

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

相关问题 Google Drive API Quickstart.py 错误 400:redirect_uri_mismatch - Google Drive API Quickstart.py Error 400: redirect_uri_mismatch 适用于我的 Google Sheets 电子表格的 Python quickstart.py - Python quickstart.py adapted to my Google Sheets spreadsheet Google API quickstart.py 错误 KeyError: &#39;_module&#39; - Google API quickstart.py error KeyError: '_module' 由于 JSONDecodeError:额外数据,Google 的 quickstart.py 未连接到 Google Workspace API - Google's quickstart.py not connecting to Google Workspace API because of JSONDecodeError: Extra data Google Drive SDK Python快速入门示例 - Google Drive SDK Python Quickstart Sample 将代码放在Google Glass快速入门的Python中 - Where to put code in Google Glass quickstart for Python Google云端硬盘快速入门Python-Localhost未发送任何数据 - Google Drive Quickstart Python - Localhost didn't send any data Gmail API quickstart.py脚本返回KeyError&#39;_module&#39; - Gmail API quickstart.py script returns KeyError '_module' 由于硒问题,Quickstart.py无法运行 - Quickstart.py failed to run due to selenium issue 为Google Drive API Python实现保存了〜/ .credentials / drive-python-quickstart.json在哪里? - Where is ~/.credentials/drive-python-quickstart.json saved for Google Drive API Python Implementation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM