ezgmail
ezgmail copied to clipboard
ezgmail.init() error - Cannot access token.json: No such file or directory
Hello,
Following is the code which I am running in Colab. I have downloaded the credentials.json file as well. The ezgmail.init() doesnt open the gmail window. Can you please help.
CODE import ezgmail, os os.chdir(r'/content/sample_data') ezgmail.init()
ERROR /usr/local/lib/python3.6/dist-packages/oauth2client/_helpers.py:255: UserWarning: Cannot access token.json: No such file or directory. WOuld liek to use ezgmail warnings.warn(_MISSING_FILE_MESSAGE.format(filename)) 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 /root/.local/share/jupyter/runtime/kernel-a77a494c-89e8-479d-8d36-ca423ce91cd9.json An exception has occurred, use %tb to see the full traceback.
SystemExit: 2 /usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py:2890: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D. warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
If you create a token using the gmail api quickstart app then try to run it, you get a slightly different error which may be of use
`import os, ezgmail
os.chdir(r'/Users/ellieleep/Documents/GitHub/automatetheboringwithpython/Chapter 18')
ezgmail.init()
Traceback (most recent call last):
File "", line 1, in
If you create a token using the gmail api quickstart app then try to run it, you get a slightly different error which may be of use
`import os, ezgmail
os.chdir(r'/Users/ellieleep/Documents/GitHub/automatetheboringwithpython/Chapter 18')
ezgmail.init()
Traceback (most recent call last): File "", line 1, in File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ezgmail/init.py", line 471, in init creds = store.get() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/oauth2client/client.py", line 407, in get return self.locked_get() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/oauth2client/file.py", line 54, in locked_get credentials = client.Credentials.new_from_json(content) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/oauth2client/client.py", line 302, in new_from_json module_name = data['_module'] KeyError: '_module'`
I had this same KeyError: '_module'
error.
I had run the Google gmail api quickstart (https://developers.google.com/gmail/api/quickstart/python) prior to discovering and installing ezgmail
.
@ellieleep 's comment above + the docs mentioning that a token.json
file is created, made me try deleting the token.json
file that had been created after running quickstart.py
.
After that, I reran:
import ezgmail
ezgmail.init()
And everything worked.
Hope this helps someone.
So... I just went through this rigamarole as well with Google Cloud Platform - create a project, get API, build credentials, etc., etc. In the end, I was able to generate the credentials.json file and the subsequent token.json.
However, now I am getting a KeyError: '_module' error when calling ezgmail.init(). I have the prerequisite modules and files already. All solutions say to delete the token.json file and rerun the authorization process, but this does not work - at least for me.
Here is the traceback:
File "<stdin>", line 1, in <module>
File "c:\Installs\Python\lib\site-packages\ezgmail\__init__.py", line 471, in init
creds = store.get()
File "c:\Installs\Python\lib\site-packages\oauth2client\client.py", line 407, in get
return self.locked_get()
File "c:\Installs\Python\lib\site-packages\oauth2client\file.py", line 54, in locked_get
credentials = client.Credentials.new_from_json(content)
File "c:\Installs\Python\lib\site-packages\oauth2client\client.py", line 302, in new_from_json
module_name = data['_module']
KeyError: '_module'
*** UPDATE ***
I changed a line in the ezgmail/init.py file (line 471) from:
creds = store.get()
to:
creds = None
and saved the file. Immediately upon running
import ezgmail
apparently a new token.json file is written. I then reverted the ezgmail/init.py file (line 471) back to...
creds = store.get()
... and now I can run ezgmail.init() with no issues!
This represents my limited knowledge of python and I am only just beginning, so please bear with my explanation above.