google drive api crash with desktop application - python

I use google drive application wrote a desktop application using python and everything works fine. But when I use pyinstaller to output a .exe file and run that application. A problem occurs on these lines:
if credentials is None or credentials.invalid:
credentials = run(FLOW, storage)
The authentication page shows and I allow its access. Unlike usual, there is no response after that and I found that the .exe program exits with no reason.
Anyone met this problem before? If so, how to solve it?
P.S. I traced the error now and it is as follows:
Traceback (most recent call last):
File "<string>", line 697, in <module>
File "<string>", line 562, in __init__
File "build\bdist.win32\egg\oauth2client\tools.py", line 166, in run
File "build\bdist.win32\egg\oauth2client\client.py", line 1069, in step2_exchange
File "USB\build\pyi.win32\USB\outPYZ1.pyz/httplib2", line 1544, in request
File "USB\build\pyi.win32\USB\outPYZ1.pyz/httplib2", line 1294, in _request
File "USB\build\pyi.win32\USB\outPYZ1.pyz/httplib2", line 1230, in _conn_request
File "USB\build\pyi.win32\USB\outPYZ1.pyz/httplib2", line 984, in connect
File "USB\build\pyi.win32\USB\outPYZ1.pyz/httplib2", line 80, in _ssl_wrap_socket
File "USB\build\pyi.win32\USB\outPYZ1.pyz/ssl", line 381, in wrap_socket
File "USB\build\pyi.win32\USB\outPYZ1.pyz/ssl", line 141, in __init__
ssl.SSLError: [Errno 185090050] _ssl.c:340: error:0B084002:x509 certificate rout
ines:X509_load_cert_crl_file:system lib
I saw someone encountered the similar error http://code.google.com/p/google-api-python-client/issues/detail?id=58 but the reply said it already fixed it.
I also tried the method in https://github.com/kennethreitz/requests/issues/557 but it is not working.
Does anyone know how to fix it?

I'm guessing, but this is possible related to STDIN handling on Windows exe from pyinstaller - usually this won't be available to you, so you might have to run your own custom flow.
But you can narrow it down to either:
Reading/writing from STDIN/STDOUT
Starting a local web server
Launching a browser
Since all those need to be performed when running a flow locally, and one of them is going wrong for you.
If you log STDERR to a text file, you will be able to see which part is crashing.

After digging a little bit, I found the solution based on solution provided by Dropbox api developer: https://forums.dropbox.com/topic.php?id=65523&replies=1#post-461457. This problem is basically caused by:
CA_CERTS = os.path.join(os.path.dirname(os.path.abspath(__file__ )), "cacerts.txt")
__file__ is the key that causes this problem. It cannot work normally in the executable program to find the path.
Similar problem can be found here: pyinstaller seems not to find a data file
In order to solve this problem, I change the above code into this:
CA_CERTS = os.path.join(os.path.dirname(sys.executable), "cacerts.txt")
By doing this, the .exe program will try to find cacerts.txt in the directory where .exe file is located. After compiling this into .pyc, I put cacerts.txt into .exe directory. Then the program can run normally.

Related

PyDub OSError: [WinError 6] The handle is invalid

I'm having a similar issue on Python 3.8.7, and I can't find the solution.
In my project, I'm using pydub.AudioSegment to get audio from a file and then exporting that audio in a different format. My code works perfectly when I'm running the python file directly. However, when I convert it to an executable with pyinstaller, run the program and get to the point of importing the audio with pydub, it gives me the following error:
Traceback (most recent call last):
File "main.py", line 269, in <module>
File "main.py", line 213, in convertfile
File "main.py", line 133, in cloud_upload
File "pydub\audio_segment.py", line 728, in from_file
File "pydub\utils.py", line 274, in mediainfo_json
File "subprocess.py", line 804, in __init__
File "subprocess.py", line 1142, in _get_handles
OSError: [WinError 6] The handle is invalid
pydub call in my program looks like this:
sound = AudioSegment.from_file(filepath)
sound.export(new_filepath, format="ogg",codec='libopus')
I've tried to add stdin=subprocess.DEVNULL and stdin=subprocess.PIPE in utils.py on line 274, but that didn't work either. Maybe I added them incorrectly, though, so suggestions like that are also highly appreciated.
I've managed to solve the problem only by removing --onefile option from pyinstaller and dropping ffmpeg.exe and ffprobe.exe into the resulted folder with the main.exe file.
That's not a good solution to the problem as I'd still prefer to use --onefile; but it works.
I'm still open to suggestions on how to make it work with --onefile or just generally why this is hapenning.
Chances are is that PyInstaller cannot recognize the imported plugin. Although if you are trying to make a app, I suggest using a shortcut instead, it is better due to the fact that you can customize the icon for the shortcut. It is what many apps mainly use.

Site-packages error in CKAN connected to ckanext-showcase

I have installed a CKAN Instance and I have installed the ckanext-showcase module.
Although the installation didn't raise any errors and I was able to add a few showcases when some of my users that I had set as showcase administrators started adding showcases the module has stopped working.
The page {portal.url/showcase} can't be viewed unless I am connected as system administrator. When a user or even a showcase user tries to enter the page get's an internal server error.
From that point on when I am trying to create a new system administrator from console with the paster command (http://docs.ckan.org/en/latest/maintaining/getting-started.html#create-admin-user) I get the bellow message
Traceback (most recent call last):
File "/usr/lib/ckan/default/lib/python2.7/site.py", line 703, in
main()
File "/usr/lib/ckan/default/lib/python2.7/site.py", line 683, in main
paths_in_sys = addsitepackages(paths_in_sys)
File "/usr/lib/ckan/default/lib/python2.7/site.py", line 282, in addsitepackages
addsitedir(sitedir, known_paths)
File "/usr/lib/ckan/default/lib/python2.7/site.py", line 204, in addsitedir
addpackage(sitedir, name, known_paths)
File "/usr/lib/ckan/default/lib/python2.7/site.py", line 173, in addpackage
exec(line)
File "", line 1, in
KeyError: 'ckanext'
Because I don't have the ability to install the CKAN again right now, is there any suggestions on how I to fix this?
Any help would be greatly appreciated
After looking to my server error logs I found that the error wasn't caused by the plugin ckanext-showcase but from the module ckanext-datarequests.
The first part of my problem was connected to a server error coming at a 401 Unauthorized exception not being handled at version 1.0.2 of the plugin. As soon as I upgraded to the latest version 1.0.3 the error was fixed.

How do I make Twython play nicer with Python to Exe programs?

I've made a program with Twython as the framework for accessing the Twitter Api. It works fine when ran as a python program, but after compiling it with py2exe, pyinstaller, and cxfreeze, it returns the same error:
File "twython\endpoints.pyc", line 169, in search
File "twython\api.pyc", line 263, in get
File "twython\api.pyc", line 257, in request
File "twython\api.pyc", line 165, in _request
twython.exceptions.TwythonError: [Errno 2] No such file or directory
I've made sure to include twython.exceptions when compiling. I cannot seem to get this thing to work properly as an executable. I've attempted on my computer and a fresh VM so there shouldn't be any installation issues. Any ideas?

pyinstaller and win32com

So I'm confused about how to get pyinstaller to build an application that uses win32com. I have a script that runs with no problem from IDLE or command line that interacts with excel via
xl = Dispatch('Excel.Application')
followed by some other really basic excel calls, then closes. I've seen advice to include "clsctx=pythoncom.CLSCTX_LOCAL_SERVER" as an argument to Dispatch, but it doesn't change anything. Whenever I build the script, I get an error similar to this
Traceback (most recent call last):
File "<string>", line 7, in <module>
File "C:\Python27\trunk\iu.py", line 436, in importHook
mod = _self_doimport(nm, ctx, fqname)
File "C:\Python27\trunk\iu.py", line 521, in doimport
exec co in mod.__dict__
File "Myskript\build\pyi.win32\Myskript\outPYZ1.pyz/win32com.client", line 11,
in <module>
File "C:\Python27\trunk\iu.py", line 436, in importHook
mod = _self_doimport(nm, ctx, fqname)
File "C:\Python27\trunk\iu.py", line 521, in doimport
exec co in mod.__dict__
File "Myskript\build\pyi.win32\Myskript\outPYZ1.pyz/win32com.client.gencache",
line 662, in <module>
File "Myskript\build\pyi.win32\Myskript\outPYZ1.pyz/win32com.client.gencache",
line 58, in __init__
File "Myskript\build\pyi.win32\Myskript\outPYZ1.pyz/win32com.client.gencache",
line 649, in Rebuild
File "Myskript\build\pyi.win32\Myskript\outPYZ1.pyz/win32com.client.gencache",
line 65, in _SaveDicts
File "Myskript\build\pyi.win32\Myskript\outPYZ1.pyz/win32com.client.gencache",
line 141, in GetGeneratePath
IOError: [Errno 22] invalid mode ('w') or filename: 'C:\\Python27\\trunk\\Myskri
pt\\dist\\Myskript.exe?844863\\__init__.py'
That's copied from this german question http://www.python-forum.de/viewtopic.php?f=1&t=25010 but my error is basically the same. I tried to implement the advice given on that page to no avail either.
I know next to nothing about COM stuff, just hoping to get this little excel app to run.
EDIT: Also tried importing pythoncom and running "CoInitialize()" (based on this guy Call MS Access module function from Python after compiling with py2exe fails saying that his script ran fine with pyinstaller) but that didn't change anything either. Really at a loss here and appreciate any advice.
I'm not sure if you are still using py2exe, i was about to try your workaround when i stumbled into this thread:
Call MS Access module function from Python after compiling with py2exe fails
The "solution" was using Pyinstaller that has a bunch of workarounds implemented on by default depending on your script. I tried it with my pywin32 script that uses excel and word com objects and it worked perfectly without any tweaks.

importing pywiiuse to test out

This is probably a simple problem. But I downloaded the pywiiuse library from here and I also downloaded the examples. However when I try to run one of the examples I end up with import issues. I'm not certain I have everything configured properly to run. One error I receive when trying to run example.py:
Press 1&2
Traceback (most recent call last):
File "example.py", line 73, in <module>
wiimotes = wiiuse.init(nmotes)
File "/home/thed0ctor/Descargas/wiiuse-0.12/wiiuse/__init__.py", line 309, in init
dll = ctypes.cdll.LoadLibrary('libwiiuse.so')
File "/usr/lib/python2.7/ctypes/__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python2.7/ctypes/__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libwiiuse.so: cannot open shared object file: No such file or directory
I'm really just starting out with this library and don't really see any documentation on how to configure pywiiuse so any help is much appreciated.
The pywiiuse library is a Python wrapper for the wiiuse C library.
Before you can use the wrapper you will first need to install the library it wraps, choose the newest version from this download page and download the appropriate installation package for you system (probably the .tar.gz since you appear to be on Linux).
add the link of libwiiuse.so to /usr/local/lib.
I also ran into this situation, I konw why it happies, but I don't konw the deep reason.

Categories

Resources