从python2迁移到python3时出现Web2py wsgihandler.py错误

时间:2018-08-24 16:57:55

标签: python-3.x apache mod-wsgi web2py wsgi

将web2py中的应用程序从python 2迁移到python 3并在本地主机中对其进行测试后,我尝试更改正在使用的服务器的配置,以使其能够与python 3一起使用。

在使服务器正常工作的许多尝试之后,我意识到我一直遇到相同的错误。 apache错误日志显示,当wsgi应该是字节字符串时,wsgi无法读取字符串,在我看来,这似乎是其中一部分配置仍在尝试使用Python 2处理该应用程序。在不重新安装整个组件的情况下,我可以采取哪些步骤将Apache的配置文件完全转换为python3?

以下是我尝试过的事情的详细信息:

-使用update-alternatives更改默认的python版本

-使用virtualEnv专门与python 3一起运行应用程序

-使用不同的方法重新安装mod_wsgi,以指定要使用python3并确保在之后启用它

-重写启用了mods的文件夹中的.load和.conf文件。

-更新web2py版本

我的想法不多了,非常感谢您的帮助。 当前,这是重新安装mod_wsgi(并可能在此过程中搞砸了)之后apache2中的错误日志:

[Fri Aug 24 10:07:19.397596 2018] [wsgi:error] [pid 6352:tid 140375914997504] <class 'int'>
[Fri Aug 24 10:07:19.397681 2018] [wsgi:error] [pid 6352:tid 140375914997504] 10
[Fri Aug 24 10:07:19.739994 2018] [wsgi:error] [pid 6352:tid 140375822579456] Loads pas\xc3\xb3
[Fri Aug 24 10:07:22.785048 2018] [wsgi:error] [pid 6352:tid 140375822579456] <class 'int'>
[Fri Aug 24 10:07:22.785121 2018] [wsgi:error] [pid 6352:tid 140375822579456] 10
[Fri Aug 24 10:07:23.022198 2018] [wsgi:error] [pid 6352:tid 140375830980352] Loads pas\xc3\xb3
[Fri Aug 24 10:40:31.558114 2018] [mpm_event:notice] [pid 6348:tid 140376080840576] AH00491: caught SIGTERM, shutting down

我的Apache配置文件:

apache.conf

WSGIDaemonProcess web2py user=www-data group=www-data


<VirtualHost *:80>

########################  Web2Py  ###############

WSGIProcessGroup web2py
WSGIScriptAlias / /home/www-data/web2py/wsgihandler.py
WSGIPassAuthorization On

    <Directory /home/www-data/web2py>
        AllowOverride None
        Require all denied
        <Files wsgihandler.py>
            Require all granted
        </Files>
    </Directory>

  AliasMatch ^/([^/]+)/static/(?:_[\d]+.[\d]+.[\d]+/)?(.*) \
        /home/www-data/web2py/applications/$1/static/$2

  <Directory /home/www-data/web2py/applications/*/static/>
    Options -Indexes
    ExpiresActive On
    ExpiresDefault "access plus 1 hour"
    Require all granted
  </Directory>

  CustomLog /var/log/apache2/access.log common
  ErrorLog /var/log/apache2/error.log

</VirtualHost>

<VirtualHost *:443>
  SSLEngine on
  SSLCertificateFile /etc/apache2/ssl/self_signed.cert
  SSLCertificateKeyFile /etc/apache2/ssl/self_signed.key

  WSGIProcessGroup web2py
  WSGIScriptAlias / /home/www-data/web2py/wsgihandler.py
  WSGIPassAuthorization On

  <Directory /home/www-data/web2py>
    AllowOverride None
    Require all denied
    <Files wsgihandler.py>
      Require all granted
    </Files>
  </Directory>
AliasMatch ^/([^/]+)/static/(?:_[\d]+.[\d]+.[\d]+/)?(.*) \
        /home/www-data/web2py/applications/$1/static/$2

  <Directory /home/www-data/web2py/applications/*/static/>
    Options -Indexes
    ExpiresActive On
    ExpiresDefault "access plus 1 hour"
    Require all granted
  </Directory>

  CustomLog /var/log/apache2/ssl-access.log common
  ErrorLog /var/log/apache2/error.log
</VirtualHost>

wsgihandler.py:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
This file is part of the web2py Web Framework
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)


This is a WSGI handler
"""
import os
import sys
sys.path.insert(0, '/home/www-data/web2py')

# change these parameters as required
LOGGING = False
SOFTCRON = False

path = os.path.dirname(os.path.abspath(__file__))
os.chdir(path)

if not os.path.isdir('applications'):
    raise RuntimeError('Running from the wrong folder')

sys.path = [path] + [p for p in sys.path if not p == path]

import gluon.main

if LOGGING:
    application = gluon.main.appfactory(wsgiapp=gluon.main.wsgibase,
                                        logfilename='httpserver.log',
                                        profiler_dir=None)
else:
    application = gluon.main.wsgibase

if SOFTCRON:
    from gluon.settings import global_settings
    global_settings.web2py_crontype = 'soft'

启用了mods / wsgi.conf:

WSGIScriptAlias / /home/www-data/web2py/wsgihandler.py

启用了mods / wsgi.load:

LoadModule wsgi_module modules/mod_wsgi.so

0 个答案:

没有答案