Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception in GRPC when trying to execute Google Cloud API #5774

Closed
wcordeiro opened this issue Aug 8, 2018 · 14 comments
Closed

Exception in GRPC when trying to execute Google Cloud API #5774

wcordeiro opened this issue Aug 8, 2018 · 14 comments
Assignees
Labels
api: core packaging type: question Request for information or clarification. Not an issue.

Comments

@wcordeiro
Copy link

I am having a problem when I generate an exe file with pyinstaller. My code runs okay when I execute using the python interpreter but when I generate the exe file using the PyInstaller I get a GRPC error.

Error: Exception in 'grpc._cython.cygrpc.ssl_roots_override_callback' ignored E0807 20:38:36.262000000 10808 src/core/lib/security/security_connector/security_connector.cc:1173] assertion failed: pem_root_certs != nullptr

The error happen when I try to execute a long_running_recognize.

Any tips regarding this problem?

@tseaver tseaver added type: question Request for information or clarification. Not an issue. packaging api: core labels Aug 8, 2018
@tseaver
Copy link
Contributor

tseaver commented Aug 8, 2018

@wcordeiro I'm not really familiar with pyinstaller. We have had a couple of reports of packaging-related issues with it:

In your case, it looks as though the SSL root certificates are not present in the pyinstaller-generated EXE. There are a couple of reports of similar problems, e.g. for requests:

And this recipe:

I don't think there is anytihng we can do in google-cloud-* to fix this issue. Please feel free to keep discussing it here, though.

@tseaver tseaver closed this as completed Aug 8, 2018
@jorgecedi
Copy link

I'm not sure if this is the best solution for this problem but I just copied the roots.pem file located in site-packages/grpc/_cython/_credentials/

a = Analysis(
             ...
             binaries=binaries,
             datas=[
               ('roots.pem', 'grpc/_cython/_credentials/'),
             ],

This will pack the pem file with the app, and it will find it right away.

@randolfo75
Copy link

I'm not sure if this is the best solution for this problem but I just copied the roots.pem file located in site-packages/grpc/_cython/_credentials/

a = Analysis(
             ...
             binaries=binaries,
             datas=[
               ('roots.pem', 'grpc/_cython/_credentials/'),
             ],

This will pack the pem file with the app, and it will find it right away.

Thanks, this helped me a lot.

@HaythamMahmoud
Copy link

I'm not sure if this is the best solution for this problem but I just copied the roots.pem file located in site-packages/grpc/_cython/_credentials/

a = Analysis(
             ...
             binaries=binaries,
             datas=[
               ('roots.pem', 'grpc/_cython/_credentials/'),
             ],

This will pack the pem file with the app, and it will find it right away.

I have the same issue, so, where to copy the file you mentioned?

@randolfo75
Copy link

I have the same issue, so, where to copy the file you mentioned?

I copied to my main folder, together with my python code file, so the code above pack them in the folder 'grpc/_cython/_credentials/' in your generated pyinstaller dir.

@cbenhagen
Copy link

A PyInstaller hook called hook-grpc.py looking like this would do the trick:

from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('grpc')

Will open a PR on the PyInstaller repo for that.

@dubbySwords
Copy link

Is this solution a security risk as pem files include certificates?

@rising-stark
Copy link

@cbenhagen It did work. I have been trying for whole day today to convert my python code to .exe file.
It was a pretty tough journey. First with pyinstaller or cx_Freeze, both giving lots of errors and bit by bit I improved by the pyinstaller approach.
.....
After many hours of resolving errors, I solved the problem.
Though you didn't tell in the above code where to put the hook-grpc.py file.
Let me add on.
It should be placed in :
.............
C:\Users\ujjwa\AppData\Local\Programs\Python\Python37\Lib\site-packages\PyInstaller\hooks
................
Here replace just the initial username and python version if necessary.
Or if you are still not getting the destination,:

  1. type python.exe in windows search box in the taskbar.
  2. Choose open file location.
    Then navigate starting from .....Lib\site-packages.....

@JaffaKetchup
Copy link

Thanks very much @rising-stark and @cbenhagen for your help!

In my case it was under C:\Python39\Lib\site-packages\PyInstaller\hooks, but I'm sure this varies per installation. Once recreated, the executable worked perfectly writing to my Firebase Firestore project.

@siddhantdixit
Copy link

@rising-stark Thanks! Worked for me :) 👍🏻

@swarnim-developer
Copy link

Thanks ! It Worked for me :) 👍🏻

@gelodefaultbrain
Copy link

@cbenhagen Hello, have you made the PR? This was 2018 I think you did :D would it be fine for you to post the PR link here? Thank you!

@gelodefaultbrain
Copy link

@cbenhagen @rising-stark What a life saver both of you! THANK YOU!

@mustafasenses
Copy link

Thank you it's great 💯 @cbenhagen @rising-stark

barakplasma added a commit to barakplasma/pyinstaller-hooks-contrib that referenced this issue Apr 26, 2022
relates to common issue when packaging google cloud api via pyinstaller
googleapis/google-cloud-python#5774 (comment)
bwoodsend pushed a commit to pyinstaller/pyinstaller-hooks-contrib that referenced this issue Apr 26, 2022
Fixes to common issue when packaging google cloud api via pyinstaller
googleapis/google-cloud-python#5774 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: core packaging type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.