Django与ModWsgi和Apache不是一个有效的应用程序

时间:2017-12-08 08:11:14

标签: django macos apache mod-wsgi

这最终成为OSx MySQL配置错误的原因:相对路径问题的不安全使用,但我留下原始问题,因为读者有相同的痕迹痕迹。

所以这是一个奇怪的问题 - 我试图在运行OSx的Mac上将Django部署到Apache,ModWSGI但是遇到以下错误消息:

目标WSGI脚本' /Library/WebServer/local_biems/biems/wsgi.py'不包含WSGI应用程序

现在:

  • local_biems使用python manage.py runserver运行正常,没有沉默问题。所以我相信我的项目没有错误,可以部署。
  • 测试应用程序local_blog运行服务器和我的虚拟主机配置运行正常 - 所以我假设Apache和MODWSGI正在愉快地一起玩。
  • local_biems和local_blog在/ Library / WebServer /中彼此并排,并具有相同的权限。
  • 如果我更新虚拟主机中的文件路径,请重新启动apache并对网站进行重新加载,我会收到上述错误。
  • WSGI文件完全相同。

我可以尝试什么?我已经在get_wsgi_application()

周围尝试了try / catch语句
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)

但同样的问题。如果我删除它并坚持使用标准......

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/

虽然我刚刚评论了所有(但是1)我的应用程序。奇怪的是,这个网站正在努力删除Ubuntu VPS没问题!

好的,所以我只是将数据库设置从local_biems复制到local_blog,我得到了MYSQL错误。

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/

1 个答案:

答案 0 :(得分:0)

行。我追溯到 -

MySQL Improperly Configured Reason: unsafe use of relative path

虽然需要更新最后一个arg以反映新路径。

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

这可能是OSx特有的问题 - 这是在10.12.6。我不确定我是否会轻易找到它,因为SQL错误似乎只出现一次然后编译的文件报告了不同的错误。我发现使用

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

删除所有已编译的文件帮助。

还必须将Debug设置为True才能获得信息量较少的500错误。