0

This ended up being a OSx MySQL Improperly Configured Reason: unsafe use of relative path issue but I have left original problem incase reader has same breadcrumb trail.

So this is an odd problem - I'm trying to deploy Django to Apache, ModWSGI on a Mac running OSx but am running into the following error message:

Target WSGI script '/Library/WebServer/local_biems/biems/wsgi.py' does not contain WSGI application

Now:

  • local_biems runs ok with python manage.py runserver with no silenced issues. So I believe my project is error free and ready for deployment.
  • a test application local_blog runs ok with runserver AND with my virtual host configuration - so I'm assuming from this that Apache and MODWSGI are playing happily together.
  • local_biems and local_blog are alongside each other in the /Library/WebServer/ and have identical permissions.
  • If I update the file paths in the virtual host, restart apache and do a hard reload of the site I get the error above.
  • WSGI files are identical.

What can I try? I've tried the try/catch statement around get_wsgi_application()

try:
    application = get_wsgi_application()
    print 'WSGI without exception'
except Exception:
    print 'handling WSGI exception'
    # Error loading applications
    if 'mod_wsgi' in sys.modules:
        traceback.print_exc()
        os.kill(os.getpid(), signal.SIGINT)
        time.sleep(2.5)

but same issue. If I remove this and stick with the standard...

Fri Dec 08 08:23:15.188440 2017] [wsgi:error] [pid 16734] [client 127.0.0.1:55348] Traceback (most recent call last):, referer: http://biems.local/
[Fri Dec 08 08:23:15.188471 2017] [wsgi:error] [pid 16734] [client 127.0.0.1:55348]   File "/Library/WebServer/local_biems/biems/wsgi.py", line 16, in <module>, referer: http://biems.local/
[Fri Dec 08 08:23:15.188521 2017] [wsgi:error] [pid 16734] [client 127.0.0.1:55348]     application = get_wsgi_application(), referer: http://biems.local/
[Fri Dec 08 08:23:15.188542 2017] [wsgi:error] [pid 16734] [client 127.0.0.1:55348]   File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application, referer: http://biems.local/
[Fri Dec 08 08:23:15.188599 2017] [wsgi:error] [pid 16734] [client 127.0.0.1:55348]     django.setup(set_prefix=False), referer: http://biems.local/
[Fri Dec 08 08:23:15.188615 2017] [wsgi:error] [pid 16734] [client 127.0.0.1:55348]   File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/__init__.py", line 27, in setup, referer: http://biems.local/
[Fri Dec 08 08:23:15.188637 2017] [wsgi:error] [pid 16734] [client 127.0.0.1:55348]     apps.populate(settings.INSTALLED_APPS), referer: http://biems.local/
[Fri Dec 08 08:23:15.188650 2017] [wsgi:error] [pid 16734] [client 127.0.0.1:55348]   File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/apps/registry.py", line 78, in populate, referer: http://biems.local/
[Fri Dec 08 08:23:15.188682 2017] [wsgi:error] [pid 16734] [client 127.0.0.1:55348]     raise RuntimeError("populate() isn't reentrant"), referer: http://biems.local/
[Fri Dec 08 08:23:15.188703 2017] [wsgi:error] [pid 16734] [client 127.0.0.1:55348] RuntimeError: populate() isn't reentrant, referer: http://biems.local/

Although I have just commented out all (but 1) of my apps. Strange thing is that this same site is working on a remove Ubuntu VPS no problem!

Ok, so I just copied the database settings from local_biems to the local_blog and I get MYSQL errors.

daviesc@orion:local_biems [0]$ tail -f /var/log/apache2/local_blog.error.log 
[Fri Dec 08 08:42:57.704722 2017] [wsgi:error] [pid 16937] [client 127.0.0.1:55911]   File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/utils.py", line 115, in load_backend, referer: http://biems.local/polls/
[Fri Dec 08 08:42:57.704740 2017] [wsgi:error] [pid 16937] [client 127.0.0.1:55911]     return import_module('%s.base' % backend_name), referer: http://biems.local/polls/
[Fri Dec 08 08:42:57.704750 2017] [wsgi:error] [pid 16937] [client 127.0.0.1:55911]   File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module, referer: http://biems.local/polls/
[Fri Dec 08 08:42:57.704766 2017] [wsgi:error] [pid 16937] [client 127.0.0.1:55911]     __import__(name), referer: http://biems.local/polls/
[Fri Dec 08 08:42:57.704776 2017] [wsgi:error] [pid 16937] [client 127.0.0.1:55911]   File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 30, in <module>, referer: http://biems.local/polls/
[Fri Dec 08 08:42:57.704913 2017] [wsgi:error] [pid 16937] [client 127.0.0.1:55911]     'Did you install mysqlclient or MySQL-python?' % e, referer: http://biems.local/polls/
[Fri Dec 08 08:42:57.704934 2017] [wsgi:error] [pid 16937] [client 127.0.0.1:55911] ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib, referer: http://biems.local/polls/
[Fri Dec 08 08:42:57.704941 2017] [wsgi:error] [pid 16937] [client 127.0.0.1:55911]   Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_mysql.so, referer: http://biems.local/polls/
[Fri Dec 08 08:42:57.704946 2017] [wsgi:error] [pid 16937] [client 127.0.0.1:55911]   Reason: unsafe use of relative rpath libmysqlclient.18.dylib in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_mysql.so with restricted binary., referer: http://biems.local/polls/
[Fri Dec 08 08:42:57.704951 2017] [wsgi:error] [pid 16937] [client 127.0.0.1:55911] Did you install mysqlclient or MySQL-python?, referer: http://biems.local/polls/
Byte Insight
  • 745
  • 1
  • 6
  • 17
  • Remove all that try/except. Now what do you see in the logs? – Daniel Roseman Dec 08 '17 at 08:24
  • Was just doing exactly that... I'll edit above. – Byte Insight Dec 08 '17 at 08:25
  • Go back and find the first error after the restart, not that error you quote. That error is only a follow on error and not the root cause. The real problem will be the very first error, not subsequent ones. – Graham Dumpleton Dec 08 '17 at 08:43
  • I think I have found the error. See further update. – Byte Insight Dec 08 '17 at 08:44
  • You also should not use that try/except. Ensure you are using daemon mode of mod_wsgi and pass ``startup-timeout=15`` to ``WSGIDaemonProcess``. That is the recommended way to recover from possibly transient errors on process restart. – Graham Dumpleton Dec 08 '17 at 08:44
  • Ensure you have up to date MySQL client libraries. They don't build them properly. Not sure if they have fixed in latest versions. Search for the error about 'unsafe use of relative rpath' for libmysqlclient and should be able to find discussion about it. I can't remember what the solution is. – Graham Dumpleton Dec 08 '17 at 08:48
  • Yes - I'm just looking at https://stackoverflow.com/questions/31343299/mysql-improperly-configured-reason-unsafe-use-of-relative-path – Byte Insight Dec 08 '17 at 08:49

1 Answers1

0

OK. I traced this to -

MySQL Improperly Configured Reason: unsafe use of relative path

Although needed to update the last arg to reflect the new path.

sudo install_name_tool -change libmysqlclient.18.dylib /
/usr/local/mysql/lib/libmysqlclient.18.dylib /
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_mysql.so

It is probably a OSx specific issue - This was on 10.12.6. I'm not sure I would have found it easily because it the SQL error only seems to appear once and then the compiled files report a different error. I found using

find . -type f -name '*.pyc' -exec rm {} +

to remove all the compiled files helped.

Also have to set Debug to True not to get the less informative 500 Error.

Byte Insight
  • 745
  • 1
  • 6
  • 17