使用apache服务器时覆盖python3默认编码器 [英] overwrite python3 default encoder when using apache server

查看:106
本文介绍了使用apache服务器时覆盖python3默认编码器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个Apache服务器,该服务器提供名为 ingenious

I am running an apache server which serves a framework called ingenious

在读取带有希伯来字符的文件时获取 UnicodeDecodeError('ascii'

Getting UnicodeDecodeError('ascii' when reading a file with hebrew chars.

I已经读到您可以使用环境变量来更改python3的默认首选编码。

I've read that you can change the default preferred encoding of python3 using environment variables.

所以我编辑了 / etc / httpd / conf / httpd.conf 使用[setenv] [3]方法:

So I have edited the /etc/httpd/conf/httpd.conf using the [setenv][3] method:

SetEnv LC_ALL en_US.UTF-8
SetEnv LANG en_US.UTF-8
SetEnv LANGUAGE en_US.UTF-8
SetEnv PYTHONIOENCODING utf8

并使用 sudo服务httpd restart 重新启动服务器,但仍无法正常工作。

And restart the server using sudo service httpd restart and still not working.

我必须指出,该软件未与apache服务器(仅python3)一起运行时在本地运行。

I have to state that the software works locally when it's not running with an apache server, simply python3.

locale.getpreferredencoding() ANSI_X3.4-1968

这是 /etc/httpd/conf/httpd.conf

ServerRoot "/etc/httpd"

Listen 80

Include conf.modules.d/*.conf

User apache
Group apache

ServerAdmin me@domain.com

<Directory />
    AllowOverride none
    Require all denied
</Directory>
ErrorLog "logs/error_log"

LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
  ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

</IfModule>


<IfModule mime_module>
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>


AddDefaultCharset UTF-8

<IfModule mime_magic_module>

    MIMEMagicFile conf/magic
</IfModule>

EnableSendfile On

# Supplemental configuration

LoadModule wsgi_module /usr/lib64/python3.5/site-packages/mod_wsgi/server/mod_wsgi-py35.cpython-35m-x86_64-linux-gnu.so

WSGIScriptAlias / "/usr/bin/inginious-webapp.production"
WSGIScriptReloading On

Alias /static/common /usr/lib/python3.5/site-packages/inginious/frontend/common/static/
Alias /static/webapp /usr/lib/python3.5/site-packages/inginious/frontend/webapp/static/
Alias /static/lti /usr/lib/python3.5/site-packages/inginious/frontend/lti/static/

SetEnv LC_ALL en_US.UTF-8
SetEnv LANG en_US.UTF-8
SetEnv LANGUAGE en_US.UTF-8
SetEnv PYTHONIOENCODING utf8

<Directory "/usr/bin">
    <Files "inginious-webapp.production">
        Require all granted
    </Files>
</Directory>

<DirectoryMatch "/usr/lib/python3.5/site-packages/inginious/frontend/(.+)/static/">
    Require all granted
</DirectoryMatch>


IncludeOptional conf.d/*.conf

如何我可以进一步调试吗?

how can I further debug this?

推荐答案

阅读:

  • http://blog.dscpl.com.au/2014/09/setting-lang-and-lcall-when-using.html

这说明了有关lang / locale的问题。

This explains issues around lang/locale.

您未使用mod_wsgi守护程序模式,但应该使用daemon模式,这是推荐的方法。

You aren't using mod_wsgi daemon mode, but you should be as daemon mode is the recommended method.

  • http://blog.dscpl.com.au/2012/10/why-are-you-using-embedded-mode-of.html
  • http://modwsgi.readthedocs.io/en/develop/user-guides/checking-your-installation.html#embedded-or-daemon-mode

也请阅读以下网站的mod_wsgi文档:

Also go read the mod_wsgi documentation at:

  • http://www.modwsgi.org

这篇关于使用apache服务器时覆盖python3默认编码器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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