【问题标题】:Cannot call web.py application : wsgifunc() failed无法调用 web.py 应用程序:wsgifunc() 失败
【发布时间】:2016-10-27 14:10:46
【问题描述】:

我正在尝试在我的 apache 服务器上启动 web.py 应用程序。 但是当我尝试调用任何 REST 服务时,我收到了一个 wsgi 错误。 在我的代码下方:

urls = (
  '/publication/(.*)', 'PublicationStats',
  '/author/(.*)', 'AuthorStats',
  '/department/(.*)', 'DepartmentStats'
)
application = web.application(urls, globals()).wsgifunc()
...
if __name__ == "__main__":
  #web.config.debug = True
  application.run()

当我尝试像/author/Smith, John 一样调用我的 REST api 时,我的 Apache 服务器生成一个关于 wsgi 的奇怪错误:

[Thu Oct 27 15:54:28.614753 2016] [cgi:error] [pid 2979] [client 130.104.xxx.xxx:62194] AH01215: Traceback (most recent call last):, referer: http://test.dial.uclouvain.be/swagger/
[Thu Oct 27 15:54:28.614841 2016] [cgi:error] [pid 2979] [client 130.104.xxx.xxx:62194] AH01215:   File "/var/www/html/api/dilbert/api.py", line 377, in <module>, referer: http://localhost/swagger/
[Thu Oct 27 15:54:28.614856 2016] [cgi:error] [pid 2979] [client 130.104.xxx.xxx:62194] AH01215:     application.run(), referer: http://localhost/swagger/
[Thu Oct 27 15:54:28.614877 2016] [cgi:error] [pid 2979] [client 130.104.xxx.xxx:62194] AH01215: AttributeError: 'function' object has no attribute 'run', referer: http://localhost/swagger/
[Thu Oct 27 15:54:28.636844 2016] [cgi:error] [pid 2979] [client 130.104.xxx.xxx:62194] End of script output before headers: api.py, referer: http://localhost/swagger/

如果我只使用“web.application(urls, globals())”,它可以工作。但我需要使用 wsgifunc 因为我需要访问web.ctx.env variable

mod_wsgi 在 Apache 上安装得很好。它似乎工作正常......我希望。
感谢您的帮助

雷诺

【问题讨论】:

  • 对我来说,这听起来像是没有为您的脚本使用适当的处理程序。在您的.htaccess 文件中,您是否有此脚本的SetHandler wsgi-script

标签: python mod-wsgi wsgi web.py


【解决方案1】:

根据@sytech 的建议,我像这样更新我的 apache 配置:

<IfModule wsgi_module>
  WSGIApplicationGroup %{GLOBAL}
  WSGIScriptAlias /api/dilbert /var/www/html/api/dilbert/api.py/
  WSGIPythonPath /var/www/html/api/dilbert

  <Directory /var/www/html/api/>
    Order deny,allow
    Allow from all
    <Files *.py>
      SetHandler wsgi-script
      Options ExecCGI FollowSymLinks
    </Files>
  </Directory>
</IfModule>

【讨论】:

  • 可能无关紧要,虽然可能会混淆您的应用程序路由,但您通常不会在WSGIScriptAlias 的最后一个参数上使用斜杠。不应需要该上下文中的SetHandler wsgi-script 指令和Options 指令。更可能的问题是您的主要 Apache 配置已将 .py 映射到 cgi-script。最好将 api.py 重命名为 api.wsgi 并更改 WSGIScriptAlias 以匹配。某些发行版附带 .py 映射到 cgi-script 是愚蠢的。
猜你喜欢
  • 2012-12-17
  • 2014-03-13
  • 2020-03-24
  • 2014-12-02
  • 2012-01-22
  • 2016-01-15
  • 2014-09-05
  • 2017-11-05
  • 2021-12-05
相关资源
最近更新 更多