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

mod_wsgi and importing _psycopg #1144

Closed
edgarcosta opened this issue Aug 24, 2020 · 7 comments
Closed

mod_wsgi and importing _psycopg #1144

edgarcosta opened this issue Aug 24, 2020 · 7 comments

Comments

@edgarcosta
Copy link

This may be related to #995 but I honestly don't understand what is going on in that thread.

When trying to import psycopg2 through mod_wsgi I get the same error message:

Traceback (most recent call last):
  File "/home/psetpartners/psetpartners-git-live/psetpartners.wsgi", line 1, in <module>
    import psycopg2
  File "/home/sage/sage-9.1/local/lib/python3.7/site-packages/psycopg2/__init__.py", line 51, in <module>
    from psycopg2._psycopg import (                     # noqa
SystemError: initialization of _psycopg raised unreported exception

I have checked shared object dependencies, via ldd, of the .so file no issues arise.
I have also noticed that the mod_wsgi documentation mentions some conflicts with psycopg2, but those seem to be outdated and only about reloading the app.

Any ideas of what initialization of _psycopg raised unreported exception means?
I googled around, and the only relevant hits I found seem to be related to #995.

Any insight or help is appreciated.
Thank you in advance!

@dvarrazzo
Copy link
Member

Hello. I don't have an idea on top of my mind about what it could be.

You may try to compile psycopg2 with debug messages and check if there are errors reported at import time that might suggest us where things get stuck.

If you would like us to try and investigate you should provide something to make the issue reproducible, such as a docker image.

Thank you very much!

@edgarcosta
Copy link
Author

Thank you.
After some digging I figured out that it was mod_wsgi trying to use the default python environment despite buing compiled against a different python.

@othman-na
Copy link

How did you fix this ? @edgarcosta

@edgarcosta
Copy link
Author

edgarcosta commented May 11, 2023

I returned to using gunicorn + proxy, as the python environment to use my app is delicate.

@juanrenos
Copy link

I returned to using gunicorn + proxy, as the python environment to use my app is delicate.

Can you please detail the action to solve this? Thank you

@edgarcosta
Copy link
Author

edgarcosta commented May 12, 2023

Let me try again.
This issue is due to mod_wsgi using the system python, while my wsgi needs to use a different python environment (including binary),
And thus, there are two solutions:

ps: If you don't have admin access to apache, then neither of these two solutions are going to work for you.

@dvarrazzo
Copy link
Member

The sooner you get rid of mod_wsgi and everything that binds to apache, the better it is for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants