【发布时间】:2015-08-20 18:25:35
【问题描述】:
我正在尝试加载具有以下内容的文件:
import os, sys
sys.path.append('/opt/graphite/webapp')
os.environ['DJANGO_SETTINGS_MODULE'] = 'graphite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
我不断收到此错误:
Target WSGI script '/opt/graphite/conf/graphite.wsgi' cannot be loaded as Python module.
当我在命令行上调出 Python 并尝试按如下方式加载此模块时,我没有收到任何错误:
import django.core.handlers.wsgi
我检查了 django 及其所有子目录的权限。有什么想法吗?
这些是apache中的错误:
Thu Aug 20 14:37:23 2015] [info] [client 26.16.7.183] mod_wsgi (pid=1812, process='graphite', application=''): Loading WSGI script '/opt/graphite/conf/graphite.wsgi'.
[Thu Aug 20 14:37:23 2015] [error] [client 26.16.7.183] mod_wsgi (pid=1812): Target WSGI script '/opt/graphite/conf/graphite.wsgi' cannot be loaded as Python module.
[Thu Aug 20 14:37:23 2015] [error] [client 26.16.7.183] mod_wsgi (pid=1812): Exception occurred processing WSGI script '/opt/graphite/conf/graphite.wsgi'.
[Thu Aug 20 14:37:23 2015] [error] [client 26.16.7.183] Traceback (most recent call last):
[Thu Aug 20 14:37:23 2015] [error] [client 26.16.7.183] File "/opt/graphite/conf/graphite.wsgi", line 5, in <module>
[Thu Aug 20 14:37:23 2015] [error] [client 26.16.7.183] import django.core.handlers.wsgi
[Thu Aug 20 14:37:23 2015] [error] [client 26.16.7.183] ImportError: No module named django.core.handlers.wsgi
[Thu Aug 20 14:37:23 2015] [debug] mod_headers.c(743): headers: ap_headers_output_filter()
这是我的 apache 石墨配置文件:
=================
Listen 8090
LoadModule wsgi_module /usr/lib64/apache2/mod_wsgi.so
WSGISocketPrefix /etc/apache2/wsgi
<Directory /opt/graphite/webapp>
Options All
AllowOverride All
Order deny,allow
Allow from all
</Directory>
DocumentRoot "/opt/graphite/webapp"
#
<VirtualHost *:8090>
ServerName 192.168.101.2
Header set Access-Control-Allow-Origin "*"
DocumentRoot "/opt/graphite/webapp"
WSGIDaemonProcess graphite processes=20 threads=20 display-name='%{GROUP}' inactivity-timeout=120
WSGIProcessGroup graphite
#
WSGIApplicationGroup %{GLOBAL}
WSGIImportScript /opt/graphite/conf/graphite.wsgi process-group=graphite application-group=%{GLOBAL}
WSGIScriptAlias / /opt/graphite/conf/graphite.wsgi
Alias /static/ /opt/graphite/webapp/content/
<Location "/content/">
SetHandler None
</Location>
#
Alias /media/ "/usr/local/lib64/python2.6/site-packages/django/contrib/admin/media/"
#
<Location "/media/">
SetHandler None
</Location>
<Directory /opt/graphite/conf/>
Allow from all
</Directory>
#
LogLevel debug
ErrorLog /var/log/apache2/graphite_error
</VirtualHost>
它一直给我关于这个文件的错误:
/opt/graphite/conf/graphite.wsgi
[Fri Aug 21 13:04:52 2015] [info] [client 29.0.213.18] mod_wsgi (pid=11626, process='graphite', application=''): Loading WSGI script '/opt/graphite/conf/graphite.wsgi'.
[Fri Aug 21 13:04:52 2015] [error] [client 29.0.213.18] mod_wsgi (pid=11626): Target WSGI script '/opt/graphite/conf/graphite.wsgi' cannot be loaded as Python module.
[Fri Aug 21 13:04:52 2015] [error] [client 29.0.213.18] mod_wsgi (pid=11626): Exception occurred processing WSGI script '/opt/graphite/conf/graphite.wsgi'.
当我在 shell 上并发出问题时:
python /opt/graphite/conf/graphite.wsgi
我没有错误。不知道这里有什么问题?
【问题讨论】: