使用apache服务器时覆盖python3默认编码器

2024-01-18

我正在运行一个 apache 服务器,它服务于一个名为巧妙 http://inginious.readthedocs.io/

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

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

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

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

并使用重新启动服务器sudo service httpd restart但仍然不工作。

我必须声明,当该软件不与 apache 服务器一起运行时,它可以在本地运行,只需使用 python3。

locale.getpreferredencoding() is ANSI_X3.4-1968改变后

这是内容/etc/httpd/conf/httpd.conf

ServerRoot "/etc/httpd"

Listen 80

Include conf.modules.d/*.conf

User apache
Group apache

ServerAdmin [email protected] /cdn-cgi/l/email-protection

<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

我怎样才能进一步调试这个?


Read:

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

这解释了有关 lang/locale 的问题。

您没有使用 mod_wsgi 守护进程模式,但您应该使用守护进程模式,因为守护进程模式是推荐的方法。

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

另请阅读 mod_wsgi 文档:

  • http://www.modwsgi.org http://www.modwsgi.org
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用apache服务器时覆盖python3默认编码器 的相关文章

随机推荐

  • perl排序问题

    我有一些巨大的日志文件需要排序 所有条目都有一个 32 位十六进制数字 这是我想要使用的排序键 有些条目是单行的 例如 bla bla bla 0x97860afa bla bla 其他的有点复杂 从上面相同类型的行开始 扩展到用大括号标记
  • Cesium:矩形实体上的自定义材质

    我正在尝试添加一个具有多种不同属性的实体 例如材质 主要是 alpha 和旋转 矩形图形已覆盖旋转 并且在我设置材质来表示纹理时起作用 viewer entities add name Site Layer rectangle coordi
  • 使用 OneToMany 的 Spring Data Projection 返回太多结果

    我有一个具有一对多关系 ContactInfo 的 JPA 实体 Person Entity public class Person Id GeneratedValue private Integer id private String n
  • Android 在 NativeScript 中不显示字体图标

    我正在尝试将 Ionicons 与 Android 和 NativeScript 一起使用 我已经包括了ionicon ttf文件和我的集合font family Ionicons 它可以在 iOS 上运行 但不能在 Android 上运行
  • GCHandle.FromIntPointer 未按预期工作

    这是一个非常简单 完整 的程序 用于练习 GCHandle FromIntPointer 的使用 using System using System Runtime InteropServices namespace GCHandleBug
  • CoTURN:如何使用 TURN REST API?

    我已经构建了 coturn 并成功运行它 ip 192 168 1 111 现在我面临的问题是通过REST API获取Turn凭证 https datatracker ietf org doc html draft uberti behav
  • 这是使用异常的正确方法吗?

    我有一个会员例外 如下所示 public enum MembershipError EmailNotFound EmailNotConfirmed IncorrectPassword EmailExists public class Mem
  • 如何设置本地环境以使用 Chrome 的最新 SameSite cookie 更改?

    我正在使用 ReactJS 构建一个应用程序 并且随着 Chrome 的最新更改 我们无法取回 cookie 因为它是由中央身份验证服务提供的 当然 在产品中它将与 JS 应用程序具有相同的域 但目前它正在本地破坏该应用程序 我知道关于Sa
  • 当 UILabel 文本属性设置为 nil 或“”时,会使 UILabel 从视图中消失(Swift / Autolayout / iOS9.1)

    我正在学习斯坦福 2015 年冬季 Swift iOS 课程 在做作业时 我遇到了一个我想改变的行为 我使用视频中描述的自动布局 使显示引脚指向前视图边缘和后视图边缘 并且计算器应用程序 显示 UILabel 可以使用初始值为 0 的值 并
  • 如何在 sqlalchemy 中查询类内部

    我有一个与 Item 类具有一对多关系的 User 类 class User Base items relationship Item def method self for item in self items if self items
  • 用于解压缩的免费 JPEG2000 库或 SDK [关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • C# Windows 无法在顶部打开

    我编写了一个相对较大的应用程序 其中有很多对话框和表单等 我用以下命令打开它们Form ShowDialog 很多时候 表单在现有窗口后面打开 例如昨天 我在一台打开了其他几个程序的机器上测试它 许多 Windows 资源管理器窗口 一些
  • 学说 2 多对多(产品 - 类别)

    您好 我在项目 产品 和类别之间有多对多的关系 我使用这三个实体实现 项目实体 Entity Table name items use Doctrine Common Collections ArrayCollection class It
  • Node.js require() 与 RequireJS?

    你好 使用 RequireJS 我可以设置这样的基本路径 base app 所以当我在 app foo bar 例如 我有一个使用的脚本require foo 然后 RequireJS 会搜索 app foo js并且不在node modu
  • 分割空格分隔的字符串

    String numbers 5 1 5 1 那么 是不是 String splitNumbers numbers split or String splitNumbers numbers split s 寻找 5 1 5 1 知道为什么两
  • 如何在maven中保护和加密setting.xml密码文件?

    如何保护 maven 中 settings xml 中的服务器 代理设置 我认为这主要是关于存储在那里的登录名和密码 并且我认为这些不能明确地放置在那里 它们应该存储在环境变量 等中吗 安全settings xml 的示例应该是什么样子 您
  • 获取存储库中的所有文件夹和文档 Alfresco Restful

    我正在学习露天 我想使用 Restful API 获取存储库中的所有文件夹和文档 我怎样才能做到这一点 网页脚本是构建您自己的 API 的好方法 但在这种情况下 您应该可以使用 Alfresco 为您提供的 OOTB 内置 API 您可以使
  • MVC 与区域 - Html.ActionLink 返回错误的 URL/路线?

    我正在使用 MVC3 并在我的应用程序中有区域 一般来说 一切正常 我可以导航到我的区域 例如 Admin Area Controller Department 如下所示 然而 我注意到 如果我没有在 ActionLink 中指定区域 例如
  • 在循环内增加时间 15 分钟[重复]

    这个问题在这里已经有答案了 我想创建一个下拉菜单 它将当前时间作为开始时间 直到 24 小时为止 就像直到 24 小时之前 所以在这之间它将显示每 15 分钟增量的时间 问题是 当我尝试运行循环时 起始时间还可以 但在下一个循环中 时间会跳
  • 使用apache服务器时覆盖python3默认编码器

    我正在运行一个 apache 服务器 它服务于一个名为巧妙 http inginious readthedocs io Getting UnicodeDecodeError ascii 读取带有希伯来字符的文件时 我读到您可以使用环境变量更