mod_wsgi报告金字塔模块中的语法错误

时间:2013-02-04 18:38:42

标签: python apache mod-wsgi pyramid

我刚刚完成安装mod_wsgi,但是我在启动Pyramid应用程序时遇到了问题。

我在CentOS 5.8上使用python 2.7,Apache 2.2.3,mod_wsgi 3.4

这是我的httpd.config文件

WSGISocketPrefix run/wsgi

<VirtualHost *:80>
 ServerName  myapp.domain.com
 ServerAlias myapp
 WSGIApplicationGroup %{GLOBAL}
 WSGIPassAuthorization On
 WSGIDaemonProcess pyramid user=apache group=apache  processes=1 threads=4 \
   python-path=/var/wsgi_sites/site-packages
 WSGIScriptAlias / /var/wsgi_sites/myapp/apache.wsgi

<Directory /var/wsgi_sites/myapp>
  WSGIProcessGroup pyramid
  Order allow,deny
  Allow from all
</Directory>

  LogLevel debug
  ErrorLog /var/log/httpd/myapp_error
</VirtualHost>

我已经给了Apache所有的site-package,python-eggs和myapp文件夹。

我用来创建WSGI应用程序的模块appache.wsgi包含以下代码

import os
os.environ['PYTHON_EGG_CACHE'] = '/var/wsgi_sites/python-eggs'

from pyramid.paster import get_app
application = get_app('/var/wsgi_sites/myapp/development.ini','main')

当我重新启动Apache并尝试访问应用程序时,我收到以下错误

mod_wsgi (pid=14842, process='pyramid', application=''): Loading WSGI script '/var/wsgi_sites/myapp/apache.wsgi'.
mod_wsgi (pid=14842): Target WSGI script '/var/wsgi_sites/myapp/apache.wsgi' cannot be loaded as Python module.
mod_wsgi (pid=14842): Exception occurred processing WSGI script '/var/wsgi_sites/myapp/apache.wsgi'.
Traceback (most recent call last):
File "/var/wsgi_sites/myapp/apache.wsgi", line 4, in ?
from pyramid.paster import get_app
File "/var/wsgi_sites/site-packages/pyramid-1.3.2-py2.7.egg/pyramid/__init__.py", line 1, in ?
from pyramid.request import Request
File "/var/wsgi_sites/site-packages/pyramid-1.3.2-py2.7.egg/pyramid/request.py", line 
class Request(BaseRequest, DeprecatedRequestMethodsMixin, URLMethodsMixin,
    ^
SyntaxError: invalid syntax

我尝试查看request.py文件,但没有语法错误。

2 个答案:

答案 0 :(得分:5)

通常当你遇到语法错误时,前一行就是罪魁祸首。看the Pyramid source,我们看到前一行是:

@implementer(IRequest)

这是一个类装饰器。在2.6版本中,类装饰器被添加到Python中。 CentOS 5.8上的默认Python版本是2.4。

您的解决方案是:  1.使用具有更新版本的Python的操作系统,或者  2.确保您的Pyramid应用程序使用2.7版。这涉及安装Python 2.7 以及系统的默认Python安装,该安装由其他应用程序使用,必须保持不变。

如果您选择安装2.7,您将执行以下操作:

$ wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
$ tar xf Python-2.7.3.tar.bz2
$ cd Python-2.7.3
$ ./configure --prefix=/usr/local
$ make && make altinstall

答案 1 :(得分:0)

我看到错误中提到了两个不同的wsgi文件

/var/wsgi_sites/project_name_api/apache.wsgi

/var/wsgi_sites/myapp/apache.wsgi

我在您粘贴的httpd.conf中看不到任何project_name路径引用。

您可能希望从审核开始。如果问题仍然存在,请发布其他信息以帮助您进一步解决问题。