EZGmail not able to locate credentials.json file - python

I'm following along with Automate the Boring Stuff's "Sending and Receiving Email with the Gmail API" section, but I'm unable to get the ezgmail API set up. I'm using Jupyter Notebook if that makes any difference.
I've downloaded the gmail API, and run their Quickstart with no issues, but when I try to run the code from the book, I get an error that the system can't find the .json file. Here's my code, which is exactly as is it in the book (with the exception of the file path, which I've changed to 'C:\path\to' just for this):
import ezgmail, os
os.chdir(r'C:\path\to\PythonScripts\credentials_json_file') #I have correct file path in my code
ezgmail.init()
And I get the error:
---------------------------------------------------------------------------
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'
I've double checked that the credentials file is in my current working directory with os.listdir, and the file shows up in the output. I've also tried to change the "credentials_json_file" part of the code to "credentials.json_file", remove the word file, json, etc., along with renaming the json file to credentials-gmail.json (as some related posts here suggest), but nothing works.
I've also tried running the code without the os.chdir line, but that just results in the following exception:
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
any help would be GREAT. I've been messing with this for way too long for such a simple introductory piece of code....

Related

Convert python file into exe using auto-py-to-exe

I have just finished a project where I have made a connect 4 game and am trying to convert it to an exe file using auto-py-to-exe.
I want to use the one-file option, however every time it finishes and I run it, it would come up with an error:
Failed to execute script 'main' due to unhandled exception: No file 'Assets/icon.png' found in working directory '...'
Then in the box it says:
Traceback (most recent call last):
File "main.py", line 32, in <module>
FileNotFoundError: No file 'Assets/window-icon.png' found in working directory '...'.
I've tried quite a few alterations, e.g. not using the image, but then it would come up with the same error but for a different added file.
How can I fix this?
EDIT: I've tried it again by using the os module and giving the full directories to all the files in main.py, but that hasn't changed anything.
I was also facing this problem then I got the solutions from analysing other threads.
You have to update your script by adding this function
import sys
import os
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
base_path=getattr(sys,'_MEIPASS',os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)
and changing address of every additional files used in your script
for example
icon = resource_path("game.icon")
You just have to use auto-py-to-exe just like shown below
Showing the options you can just use
Add all the files used in the Additional File section of it and make sure that the period(.) is there in the destination
That's it !

Get more info out of a Python3 OSError

I am using Python3 on Ubuntu with the HID module python3-hid.
If I use it to open a device, I simply get back:
OSError: open failed
Which prompted me to handle the exception, and see if I can get more information out of it:
try:
h.open(vend, prod)
except OSError as error :
print(error)
print(error.strerror)
print(error.filename)
sys.exit(1)
To my surprise, no further information was available, as both strerror and filename were None.
open failed
None
None
NOTE: My open() succeeds when I run as root, so I know this is a permission thing. But why can't this OSError tell me that it is permission related?
How do I get all the details (specific reason of failure, and filename involved) out of an OSError?
UPDATE: The traceback leads to hid.pyx file:
Traceback (most recent call last):
File "/tmp/./tst.py", line 30, in <module>
h.open(vend, prod)
File "hid.pyx", line 66, in hid.device.open
I am not sure why my system can't find the hid.pyx file.
$ dpkg -S hid.pyx
dpkg-query: no path found matching pattern *hid.pyx*
Checking the upstream package from Ubuntu... it turns out that python3-hid is part of the software for a crypto coin wallet? Strange. I think I will skip using this module, and maybe write directly in C, using libhidapi-hidraw which this python module also uses.

Can't run snakeviz. What might be the problem here?

When I ran $ snakeviz code_profile.prof from CLI :
snakeviz web server started on 127.0.0.1:8080; enter Ctrl-C to exit http://127.0.0.1:8080/snakeviz/%2Fhome%2Fatmadeep%2FProjects%2FtrafficAI-master%2Fprofile_info-60.prof snakeviz: error: no web browser found: could not locate runnable browser
After some search, I tried running it in server only mode and got this error using --server argument :
Traceback (most recent call last): File "/home/atmadeep/anaconda3/envs/work-env/lib/python3.7/site-packages/tornado/web.py", line 1681, in _execute result = self.prepare() File "/home/atmadeep/anaconda3/envs/work-env/lib/python3.7/site-packages/tornado/web.py", line 2430, in prepare raise HTTPError(self._status_code) tornado.web.HTTPError: HTTP 404: Not Found
What might be the problem here? Is the profile generated corrupt or am I not understanding something related to snakeviz.
Note: I'm not running this code in jupyter-notebook.
So, here's the solution. from the console, run:
$python -m snakeviz profile.prof --server
When running from console, snakeviz needs to be called as shown above.
on a server you have to add --server argument and to click on the link in the terminal. Putting a threshold at 1/100 helps also.

Python build failed

I was trying to build python from source. Durring
$make test
this error arose and caused the build to fail.
====================================================================== ERROR: test_idna (test.test_socket.GeneralModuleTests)
---------------------------------------------------------------------- Traceback (most recent call last): File
"/home/h/Downloads/Python-3.4.2/Lib/test/test_socket.py", line 1287,
in test_idna
socket.gethostbyname('испытание.python.org') socket.gaierror: [Errno -5] No address associated with hostname
---------------------------------------------------------------------- Ran 506 tests in 150.098s
FAILED (errors=1, skipped=24) test test_socket failed make: *** [test]
Error 1
Im sketched by having the russian URL in the source of python. Was python hacked?
what is this? It translates into ispytanie.python.org
but i still have no clue why its there.
UPDATE:
http://ispytanie.python.org/
the page which was the translation, of the Russian page, no longer works.
anyone who follows the directions for a Linux install, running $make test
will likely encounter this error.
I edited Python-3.4.2/Lib/test/test_socket.py and removed 3 instances of Russian URLs, replacing them with 'python.org' which now allows for $make test to succeed.

Why do i get this traceback error?

This is the error i get:
Traceback (most recent call last):
File "dwload.py", line 9, in <module>
File "Pmw\__init__.pyc", line 28, in <module>
WindowsError: [Error 3] The system cannot find the path specified: "C:\\Users\\P
'sao\\Desktop\\dist\\library.zip\\Pmw/*.*"
I get the error after compiling the python file into the executable with py2exe.
Does anybody know why i get this error?
Found the solution: http://billyjin.kodingen.com/punbb-1.3.4/viewtopic.php?id=310
Well, the error message says that the path was not found, and if you look at the path, you appear to have mixed up backslashes and slashes as path separators. How are you constructing the path you're using?
I had the same problem when using pyinstaller and tkinter table (py 2.7). The problem was solved by removing the Pwm dependency in the tkintertable lib metadata. Its will help you, if pwm dont used in program
Finally, I found the solution:
First, you need to run the bundlepmw.py in the C:\Python27\Lib\site-packages\Pmw\build\lib\Pmw\Pmw_1_3\bin folder following this command: python bundlepmw.py C:\Python27\Lib\site-packages\Pmw\Pmw_1_3\lib to create the Pmw.py.
Read this page: folk.uio.no/hpl/scripting/doc/python/Pmw/dynamicloader.html, after fixing the bundlepmw.py based on this link sourceforge.net/p/pmw/discussion/33675/thread/f0bd7f34.
You should be able to generate the Pmw.py file.
Then copy the Pmw.py plus PmwBlt.py and PmwColor.py into the main script directory and run your setup.py. Sweet

Categories