EZGmail无法找到凭据.json文件

时间:2020-09-28 17:07:23

标签: python json python-3.x gmail-api

我正在关注“自动完成无聊的事情”的“使用Gmail API发送和接收电子邮件”部分,但是我无法设置ezgmail API。如果这有任何区别,我正在使用Jupyter Notebook。 我已经下载了gmail API,并没有任何问题地运行它们的快速入门,但是当我尝试从书中运行代码时,出现一个错误,提示系统找不到.json文件。这是我的代码,与书中的代码完全一样(文件路径除外,为此我将其更改为“ C:\ path \ to”):

import ezgmail, os
os.chdir(r'C:\path\to\PythonScripts\credentials_json_file') #I have correct file path in my code
ezgmail.init()

我得到了错误:

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-13-ed031accfb24> in <module>
      1 import ezgmail, os
----> 2 os.chdir(r'C:\path\to\PythonScripts\credentials_json_file')
      3 ezgmail.init()

FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\path\to\\PythonScripts\\credentials_json_file'

我用os.listdir再次检查了凭证文件是否在我当前的工作目录中,并且该文件显示在输出中。我还尝试将代码的“ credentials_json_file”部分更改为“ credentials.json_file”,删除word文件,json等,并将json文件重命名为凭据-gmail.json(如此处的一些相关文章)建议),但无济于事。

我还尝试了在不使用os.chdir行的情况下运行代码,但这只会导致以下异常:

usage: ipykernel_launcher.py [--auth_host_name AUTH_HOST_NAME] [--noauth_local_webserver]
                             [--auth_host_port [AUTH_HOST_PORT [AUTH_HOST_PORT ...]]]
                             [--logging_level {DEBUG,INFO,WARNING,ERROR,CRITICAL}]
ipykernel_launcher.py: error: unrecognized arguments: -f C:\path\to\AppData\Roaming\jupyter\runtime\kernel-5b1dd877-fb2d-4b67-8b7e-88a3d365dc4a.json
An exception has occurred, use %tb to see the full traceback.

SystemExit: 2

任何帮助将是巨大的。对于这么简单的介绍性代码,我已经把它弄得太久了……。

0 个答案:

没有答案
相关问题