的Apache2和MOD WSGI:目标WSGI脚本无法加载Python模块 [英] apache2 and mod wsgi : Target WSGI script cannot be loaded as Python module

查看:6474
本文介绍了的Apache2和MOD WSGI:目标WSGI脚本无法加载Python模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上的Apache2安装mod_wsgi的,在Ubuntu。
所以,我的libapache2安装-MOD-WSGI包,我激活了他a2enmod。

I am trying to install mod_wsgi on apache2, on ubuntu. So I install libapache2-mod-wsgi package, I activate him with a2enmod.

我有一个网站(languageAnalyz),我试图用mod_wsgi的使用。
当我打电话本地主机/ languageAnalyz,我得到一个错误500。

I got a web site (languageAnalyz), that I am trying to use with mod_wsgi. When I call localhost/languageAnalyz, I got an error 500.

在日志中的Apache2,我可以看到这一点:

In apache2 log, I can see this :

[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] mod_wsgi (pid=4993): Target WSGI script '/var/www/languageAnalyz/test-wsgi.py' cannot be loaded as Python module.
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] mod_wsgi (pid=4993): SystemExit exception raised by WSGI script '/var/www/languageAnalyz/test-wsgi.py' ignored.
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1]   File "/var/www/languageAnalyz/test-wsgi.py", line 10, in <module>
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1]     WSGIServer(app).run()
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi.py", line 112, in run
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1]     sock = self._setupSocket()
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi_base.py", line 997, in _setupSocket
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1]     req.run()
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi_base.py", line 572, in run
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1]     self._end(appStatus, protocolStatus)
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi_base.py", line 601, in _end
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1]     sys.exit(appStatus)
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] SystemExit: 0

我GOOGLE了这个错误,我觉得很多解决方案(大多数时候为Django项目)。
我undsertand,就是我需要创建一个 __ __初始化。PY 文件。
我做了什么,这是我的 __ __初始化PY 文件:

__all__ = ['app','get_size_dir','get_nbrf_dir','getStats'] #name of my functions
import index # my three python files
import analyz
import test-wsgi

__ __所有名单,这是在这三个文件的函数的名称。
我只是尝试启动test-wsgi.py,并得到了同样的错误500。

In the __all__ list, this is the name of the functions in the three files. I am just trying to launch test-wsgi.py, and get the same error 500.

下面是我的test-wsgi.py文件:

Here is my test-wsgi.py file :

import os,sys
sys.path.append(os.path.dirname(__file__))
from cgi import escape,parse_qs
from flup.server.fcgi import WSGIServer
def app(environ, start_response):
  start_response('200 OK',[('Content-Type','text/plain; charset=utf-8')])
   yield "hello world!"
WSGIServer(app).run()

那么,什么是错的?
谢谢

So what's wrong ? Thank you,

编辑:
这里是我的Apache2 CONF:

Edit : here is my apache2 conf :

WSGIPythonPath /var/www/languageAnalyz
<VirtualHost *:80>
  ...
  <Directory /var/www/languageAnalyz/>
    Options +Indexes ExecCGI FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
    DirectoryIndex index.py
    SetHandler wsgi-script
  </Directory>
  ...
</VirtualHost>

Edit_bis:
于是,我试着做我的Django的文档阅读。
我改变我的Apache2的conf为:

Edit_bis : So I try to do as I read on django doc. I change my apache2 conf to :

WSGIPythonPath /var/www/languageAnalyz
<VirtualHost *:80>
  ...
   WSGIScriptAlias /IPA /var/www/languageAnalyz/testwsgi.py
    <Directory /var/www/languageAnalyz/>
            Options +Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            Allow from all
            DirectoryIndex testwsgi.py
    </Directory>

  ...
</VirtualHost>

我重新启动的Apache2,我得到了同样的错误,在此之前多了一个:

I restart apache2, and I got the same error, and one more before :

[Sun Aug 25 12:47:18 2013] [notice] caught SIGTERM, shutting down
[Sun Aug 25 12:47:19 2013] [notice] FastCGI: wrapper mechanism enabled (wrapper: /usr/lib/apache2/suexec)
[Sun Aug 25 12:47:19 2013] [notice] FastCGI: process manager initialized (pid 7879)
[Sun Aug 25 12:47:19 2013] [notice] mod_python: Creating 8 session mutexes based on 150 max processes and 0 max threads.
[Sun Aug 25 12:47:19 2013] [notice] mod_python: using mutex_directory /tmp
[Sun Aug 25 12:47:19 2013] [warn] mod_wsgi: Compiled for Python/2.7.3.
[Sun Aug 25 12:47:19 2013] [warn] mod_wsgi: Runtime using Python/2.7.4.
[Sun Aug 25 12:47:19 2013] [notice] Apache/2.2.22 (Ubuntu) mod_fastcgi/mod_fastcgi-SNAP-0910052141 PHP/5.4.9-4ubuntu2.2 mod_python/3.3.1 Python/2.7.4 mod_ruby/1.2.6 Ruby/1.8.7(2012-02-08) mod_wsgi/3.4 configured$
[Sun Aug 25 12:47:19 2013] [error] WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
[Sun Aug 25 12:47:19 2013] [error] WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
[Sun Aug 25 12:47:19 2013] [error] WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
[Sun Aug 25 12:47:19 2013] [error] WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
[Sun Aug 25 12:47:19 2013] [error] Status: 200 OK\r
[Sun Aug 25 12:47:19 2013] [error] Content-Type: text/plain; charset=utf-8\r
[Sun Aug 25 12:47:19 2013] [error] \r
[Sun Aug 25 12:47:19 2013] [error] hello world!
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] mod_wsgi (pid=7884): Target WSGI script '/var/www/languageAnalyz/testwsgi.py' cannot be loaded as Python module.
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] mod_wsgi (pid=7884): SystemExit exception raised by WSGI script '/var/www/languageAnalyz/testwsgi.py' ignored.
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1]   File "/var/www/languageAnalyz/testwsgi.py", line 10, in <module>
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1]     WSGIServer(app).run()
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi.py", line 112, in run
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1]     sock = self._setupSocket()
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi_base.py", line 997, in _setupSocket
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1]     req.run()
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi_base.py", line 572, in run
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1]     self._end(appStatus, protocolStatus)
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi_base.py", line 601, in _end
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1]     sys.exit(appStatus)
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] SystemExit: 0

Edit_ter:

Edit_ter :

好吧,我刚刚成功发射testwsgi.py。我改变我的应用程序功能分为应用程序,并在结尾添加一些行:

Ok, I just successfully launch testwsgi.py. I change my app function into application, and I add some lines at the end :

if __name__ == '__main__':
  from wsgiref.simple_server import make_server
  server = make_server('localhost', 8080, application)
  server.serve_forever()

我的事件不知道,为什么它的工作,为什么它不工作之前。 ......现在我得到了一些问题,打开文件,用自己的路径(配置文件或模板文件...)

I event don't know, why it's working, why it was not working before. ... And now I got some problem to open files, with their path (config files, or templates files ...)

[Sun Aug 25 13:10:51 2013] [error] [client 127.0.0.1]   File "/var/www/languageAnalyz/analyz.py", line 22, in getStats
[Sun Aug 25 13:10:51 2013] [error] [client 127.0.0.1]     flangs=open('config/languages.yml')

我尝试用绝对路径,它没有工作过...

I try with absolute path, it didn't work too ...

推荐答案

有关我的问题是WSGI Python版本不匹配。我使用python 3,因此:

For me the problem was wsgi python version mismatch. I was using python 3, so:

$ sudo apt-get remove libapache2-mod-python libapache2-mod-wsgi
$ sudo apt-get install libapache2-mod-wsgi-py3

这篇关于的Apache2和MOD WSGI:目标WSGI脚本无法加载Python模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆