gpt4 book ai didi

python - Apache 与 mod_wsgi 发出有关 django 中数据库的错误

转载 作者:行者123 更新时间:2023-11-29 21:02:57 24 4
gpt4 key购买 nike

首先,我已经搜索并尝试了有关该主题的许多答案,但似乎没有一个有帮助。由于某种原因,我在使用 Apache 和 django 时遇到了一个奇怪的错误。这是我的设置:我正在运行 Mac OS X El Capitan,我使用的是 OS Apache 2.4,并且我已经安装了 mod_wsgi 扩展。我可以使用“runserver”命令通过终端运行 django,没有任何问题。我还在虚拟环境中运行我的 django 项目。我安装了python3,这样我就不必使用操作系统python 2。因此虚拟环境是基于python 3的。我的 django 项目使用 django 文档中推荐的 mysqlclient 驱动程序连接到 mysql。我的django版本是1.9。我已经配置了我的 apache vhost 文件以使用此 vhost 配置为我的 django 项目提供服务:

<VirtualHost *:80>

ServerName simplesurvey.proj
ServerAdmin admin@simplesurvey.proj

Alias /static /Users/UncharteD/Sites/project/survey/static/
<Directory /Users/UncharteD/Sites/project/survey/static/>
Require all granted
</Directory>

<Directory /Users/UncharteD/Sites/project/surveyproject/>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

WSGIDaemonProcess simplesurvey python-path=/Users/UncharteD/Sites/project/:/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages
WSGIProcessGroup simplesurvey
WSGIScriptAlias / /Users/UncharteD/Sites/project/surveyproject/wsgi.py

我的网络浏览器收到 500 错误状态。我已将 simplesurvey.proj 作为条目添加到我的主机文件中。以下是浏览器消息:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

我检查了我的 Apache 错误日志,它包含以下内容:

Full Apache error log

(我认为)最重要的一点是堆栈跟踪。当命令行版本可以完美完成所有操作时,为什么加载模块失败?以下是日志中的一些内容:

   [Thu May 05 18:31:52.828568 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] mod_wsgi (pid=64376): Target WSGI script '/Users/UncharteD/Sites/project/surveyproject/wsgi.py' cannot be loaded as Python module.
[Thu May 05 18:31:52.828660 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] mod_wsgi (pid=64376): Exception occurred processing WSGI script '/Users/UncharteD/Sites/project/surveyproject/wsgi.py'.
[Thu May 05 18:31:52.828681 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] Traceback (most recent call last):
[Thu May 05 18:31:52.828701 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] File "/Users/UncharteD/Sites/project/surveyproject/wsgi.py", line 16, in <module>
[Thu May 05 18:31:52.828779 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] application = get_wsgi_application()
[Thu May 05 18:31:52.828792 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Thu May 05 18:31:52.828875 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] django.setup()
[Thu May 05 18:31:52.828898 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/__init__.py", line 18, in setup
[Thu May 05 18:31:52.828973 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] apps.populate(settings.INSTALLED_APPS)
[Thu May 05 18:31:52.828991 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/apps/registry.py", line 108, in populate
[Thu May 05 18:31:52.829136 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] app_config.import_models(all_models)
[Thu May 05 18:31:52.829150 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/apps/config.py", line 202, in import_models
[Thu May 05 18:31:52.829224 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] self.models_module = import_module(models_module_name)
[Thu May 05 18:31:52.829234 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Thu May 05 18:31:52.829309 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] __import__(name)
[Thu May 05 18:31:52.829320 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] File "/Users/UncharteD/Sites/project/survey/models.py", line 22, in <module>
[Thu May 05 18:31:52.829432 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] class Genre(models.Model):
[Thu May 05 18:31:52.829441 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/db/models/base.py", line 108, in __new__
[Thu May 05 18:31:52.829807 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] new_class.add_to_class('_meta', Options(meta, app_label))
[Thu May 05 18:31:52.829817 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/db/models/base.py", line 307, in add_to_class
[Thu May 05 18:31:52.829844 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] value.contribute_to_class(cls, name)
[Thu May 05 18:31:52.829852 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/db/models/options.py", line 263, in contribute_to_class
[Thu May 05 18:31:52.830098 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
[Thu May 05 18:31:52.830109 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/db/__init__.py", line 36, in __getattr__
[Thu May 05 18:31:52.830150 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] return getattr(connections[DEFAULT_DB_ALIAS], item)
[Thu May 05 18:31:52.830158 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/db/utils.py", line 212, in __getitem__
[Thu May 05 18:31:52.830249 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] backend = load_backend(db['ENGINE'])
[Thu May 05 18:31:52.830258 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/db/utils.py", line 116, in load_backend
[Thu May 05 18:31:52.830271 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] return import_module('%s.base' % backend_name)
[Thu May 05 18:31:52.830279 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Thu May 05 18:31:52.830291 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] __import__(name)
[Thu May 05 18:31:52.830297 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] File "/Users/UncharteD/.virtualenvs/survey/lib/python3.5/site-packages/django/db/backends/mysql/base.py", line 28, in <module>
[Thu May 05 18:31:52.830400 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
[Thu May 05 18:31:52.830420 2016] [wsgi:error] [pid 64376] [remote 127.0.0.1:0] ImproperlyConfigured: Error loading MySQLdb module: No module named _mysql

任何有关如何解决此问题的帮助将不胜感激。谢谢

最佳答案

也许是权限问题?

Apache 有自己的用户,因此该用户可能无权访问您的 virtualenv 路径,特别是因为它位于用户文件夹内。这通常可以通过将 apache 用户添加到您的用户组来解决。

至少我知道 Linux 上是这样工作的,我猜 Mac 上也差不多?

关于python - Apache 与 mod_wsgi 发出有关 django 中数据库的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37057991/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com