Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errno 185090050 _ssl.c:343: error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib, after packaging to exe by PyInstaller

I code a python script to check files in GCS, it uses wxpython to generate the GUI. To authenticate I did it in this way(following the way in Google sample code -> http://code.google.com/p/google-cloud-platform-samples/source/browse/file-transfer-json/chunked_transfer.py?repo=storage):

flow = flow_from_clientsecrets(CLIENT_SECRETS_FILE, 
                                # the secrets file I put in same folder
                               scope=scope,
                               message=MISSING_CLIENT_SECRETS_MESSAGE)

credential_storage = CredentialStorage(CREDENTIALS_FILE) # the file to store
                                                    # authentication credentials
credentials = credential_storage.get()
if credentials is None or credentials.invalid:
    credentials = run_oauth2(flow, credential_storage)

self.printLog('Constructing Google Cloud Storage service...')
http = credentials.authorize(httplib2.Http())
return discovery_build('storage', 'v1beta1', http=http)

The codes above are contained in my Python script, which works very well when it is just a python .py file, later I used pyinstaller convert it to .exe in win 7 64bit(I also put the secret file in the same folder as the .exe file) using below command

C:\gcs_file_check>python pyinstaller-2.0\pyinstaller.py -w gcs_file_check.py

When clicking on the exe, the Request for Permission page from Google was launched correctly(as what it is as running Python script not exe), but after I click Accept, the above code will throw exception:

[Errno 185090050] _ssl.c:343: error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib

And I can see the file credentials.json is not created by .exe, while the Python script can create this file correctly.

Could someone know how this happens and how to fix? Appreciate every answer!

===================

updated on 04/16:

I added debugging code and found that the exception exactly comes from below code:

if credentials is None or credentials.invalid:
    credentials = run_oauth2(flow, credential_storage)

===================

updated:

Add more detail, previously I was using oauth2client.tools.run()

from oauth2client.tools import run as run_oauth2

Now I change to run_flow() as the source code suggested -> https://google-api-python-client.googlecode.com/hg/docs/epy/oauth2client.tools-pysrc.html#run

from oauth2client.tools import run_flow as run_oauth2

Now this part of code is:

parser=argparse.ArgumentParser(description=__doc__,                  
                     formatter_class=argparse.RawDescriptionHelpFormatter,
                     parents=[tools.argparser] )
                     flags = tools.argparser.parse_args(sys.argv[1:])

if credentials is None or credentials.invalid:
    credentials = run_oauth2(flow, credential_storage, flags)

But still, the python code works well, and throw the same exception [Errno 185090050] after packaging to .exe by PyInstaller.

like image 941
Reed_Xia Avatar asked Nov 02 '22 01:11

Reed_Xia


1 Answers

try this, https://github.com/kennethreitz/requests/issues/557 "I also faced a similar error when using pyinstaller with Httplib2. You need to explicitly pass the path to ssl client cert file to the 'cert' argument http request. Also, you would need to package your. .pem file as a data file in pyinstaller."

like image 131
cgwxyz Avatar answered Nov 06 '22 22:11

cgwxyz