【发布时间】:2017-12-09 21:49:03
【问题描述】:
我已经设置了我的 Python/Django 虚拟环境,并将 mod_wsgi 设置为守护程序模式,并且很确定(以前做过)它“大部分正确”,除了我收到以下错误.. .
[Thu Jul 06 00:35:26.986363 2017] [mpm_event:notice] [pid 11442:tid 140557758930432] AH00493: SIGUSR1 received. Doing graceful restart
Exception ignored in: <object repr() failed>
Traceback (most recent call last):
File "/home/jamin/www/dev.tir.com/py361ve/lib/python3.6/site-packages/PIL/Image.py", line 572, in __del__
NameError: name 'hasattr' is not defined
[Thu Jul 06 00:35:27.194483 2017] [mpm_event:notice] [pid 11442:tid 140557758930432] AH00489: Apache/2.4.25 (Ubuntu) mod_wsgi/4.5.15 Python/3.6 configured -- resuming normal operations
[Thu Jul 06 00:35:27.194561 2017] [core:notice] [pid 11442:tid 140557758930432] AH00094: Command line: '/usr/sbin/apache2'
我的 django 应用程序本身可以通过 wsgi.py 正常加载,但它似乎与核心 python 有关(我的设置可能出错)出错了:NameError: name 'hasattr' is not defined
在浏览器中 - 我得到一个普通的“服务器错误 (500)”页面,而不是标准的 Apache“内部服务器错误”页面。
省略我的 VirtualHost 和超出此处的步骤是我为自己整理的基本步骤,如果你能发现任何东西...(我尝试了所有不同的 python 包,而不仅仅是 -venv)
Install Python 3.6 and virtualenv
sudo apt-get update
sudo apt-get install python3.6-venv
sudo apt-get install virtualenv
(or find the latest and greatest python package that includes pip https://packages.ubuntu.com/ )
Install Apache2
sudo apt-get install apache2 apache2-dev
Make and enter a folder for your project - then build a Virtual Environment in it
mkdir ~/example.com
cd ~/example.com
virtualenv --python=/usr/bin/python3.6 py361ve
Enter your new Virtual Environment to install packages to it
source py361ve/bin/activate
Install Django, mod_wsgi, and any other needed packages
pip install django
pip install mod_wsgi
pip install ...
(no need for pip3 in virtual environment - django should be the latest release)
Run following command and place output in apache config file ( in /etc/apache2/ )
mod_wsgi-express module-config
Exit your virtual environment
deactivate
(You can re-enter your virtual environment any time using the source method in step 8)
当我停止/启动/重新启动 apache2 时会发生以下情况...
apache2 stop...
[Thu Jul 06 06:01:34.190940 2017] [mpm_event:notice] [pid 2015:tid 140157449797120] AH00491: caught SIGTERM, shutting down
_______________________________________________________________
apache2 start...
[Thu Jul 06 06:02:39.076741 2017] [mpm_event:notice] [pid 2181:tid 140553545080320] AH00489: Apache/2.4.25 (Ubuntu) mod_wsgi/4.5.15 Python/3.6 configured -- resuming $
[Thu Jul 06 06:02:39.076890 2017] [core:notice] [pid 2181:tid 140553545080320] AH00094: Command line: '/usr/sbin/apache2'
_______________________________________________________________
apache2 restart...
Exception ignored in: <object repr() failed>
Traceback (most recent call last):
File "/home/jamin/www/dev.tir.com/py361ve/lib/python3.6/site-packages/PIL/Image.py", line 572, in __del__
NameError: name 'hasattr' is not defined
[Thu Jul 06 06:05:43.307877 2017] [mpm_event:notice] [pid 2181:tid 140553545080320] AH00491: caught SIGTERM, shutting down
[Thu Jul 06 06:05:43.492499 2017] [mpm_event:notice] [pid 2301:tid 140353155558912] AH00489: Apache/2.4.25 (Ubuntu) mod_wsgi/4.5.15 Python/3.6 configured -- resuming $
[Thu Jul 06 06:05:43.492705 2017] [core:notice] [pid 2301:tid 140353155558912] AH00094: Command line: '/usr/sbin/apache2'
【问题讨论】:
-
在我的情况下,这被证明是一个完全不相关的问题:当我打开登录时,我发现 django 发出 500 代码是因为模板 URL 有问题。解决后,页面开始正常运行。
hasattr错误对我来说是一个红鲱鱼。 -
@user2658323 非常感谢!在找到您的评论之前,我已经花了大约 3 个小时调试这个问题 - 事实证明,我的问题也与 Pillow 完全无关,如果在我的
settings.py中将DEBUG设置为 True 就很明显了。 . -
@martonbognar - 是的,设置中的 DEBUG = true 选项在这种情况下也救了我。我立即发现了我的问题!
-
在我的情况下,这是由 SELinux 阻止 apache 访问文件引起的。
-
Dismine - 我认为文件访问也与我的问题有关。事实上,这似乎是很多时候的问题????
标签: python django python-3.x ubuntu mod-wsgi