Search code examples
pythongoogle-drive-apipyinstallergoogle-api-python-client

google drive api crash with desktop application


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?


Solution

  • 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.