Centos

CentOS 7 / Apache / mod_wsgi - UnicodeDecodeError:‘ascii’編解碼器無法解碼位置 2727 的字節 0xc2:序數不在範圍內(128)

  • February 9, 2017

我已經使用 mod_wsgi 在 Apache (httpd) 中部署了一個 Python Web 應用程序(使用 Pyramid)。

啟動 Apache 服務後,當我們向 Web 應用程序發出 http 請求時,會出現以下錯誤(來自 Apache 日誌)…

[Mon Feb 06 16:38:55.980119 2017] [wsgi:error] [pid 16031] [remote 172.16.13.1:204] mod_wsgi (pid=16031): Target WSGI script '/usr/local/lb/ve32/src/LBGenerator/lbgenerator.wsgi' cannot be loaded as Python module.
[Mon Feb 06 16:38:55.980205 2017] [wsgi:error] [pid 16031] [remote 172.16.13.1:204] mod_wsgi (pid=16031): Exception occurred processing WSGI script '/usr/local/lb/ve32/src/LBGenerator/lbgenerator.wsgi'.
Traceback (most recent call last):
 File "/usr/local/lb/ve32/src/LBGenerator/lbgenerator.wsgi", line 1, in <module>
   from pyramid.paster import get_app
 File "/usr/local/lb/ve32/lib/python3.2/site-packages/pyramid-1.5.1-py3.2.egg/pyramid/paster.py", line 10, in <module>
   from pyramid.scripting import prepare
 File "/usr/local/lb/ve32/lib/python3.2/site-packages/pyramid-1.5.1-py3.2.egg/pyramid/scripting.py", line 1, in <module>
   from pyramid.config import global_registries
 File "/usr/local/lb/ve32/lib/python3.2/site-packages/pyramid-1.5.1-py3.2.egg/pyramid/config/__init__.py", line 30, in <module>
   from pyramid.exceptions import (
 File "/usr/local/lb/ve32/lib/python3.2/site-packages/pyramid-1.5.1-py3.2.egg/pyramid/exceptions.py", line 1, in <module>
   from pyramid.httpexceptions import (
 File "/usr/local/lb/ve32/lib/python3.2/site-packages/pyramid-1.5.1-py3.2.egg/pyramid/httpexceptions.py", line 138, in <module>
   from pyramid.response import Response
 File "/usr/local/lb/ve32/lib/python3.2/site-packages/pyramid-1.5.1-py3.2.egg/pyramid/response.py", line 23, in <module>
   init_mimetypes(mimetypes)
 File "/usr/local/lb/ve32/lib/python3.2/site-packages/pyramid-1.5.1-py3.2.egg/pyramid/response.py", line 16, in init_mimetypes
   mimetypes.init()
 File "/usr/local/lb/py32/lib/python3.2/mimetypes.py", line 351, in init
   db.read(file)
 File "/usr/local/lb/py32/lib/python3.2/mimetypes.py", line 203, in read
   self.readfp(fp, strict)
 File "/usr/local/lb/py32/lib/python3.2/mimetypes.py", line 214, in readfp
   line = fp.readline()
 File "/usr/local/lb/py32/lib/python3.2/encodings/ascii.py", line 26, in decode
   return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 2727: ordinal not in range(128)

該 web python 應用程序在所有這些發行版中都能完美執行:Ubuntu 14.04、Debian 8、RedHat 6、CentOS 6、Suse 12 和 openSUSE 13,但在 CentOS 7 中則不行… =[

我們在“CentOS 7”中使用“Python 3.2.2”、“mod_wsgi 4.3.2”和“Apache 2.4.6”。Web 應用程序建構在Pyramid Web 框架 ( http://docs.pylonsproject.org/projects/pyramid/en/latest/ ) 之上。

這是一個相當常見的錯誤!到目前為止,我還沒有找到一種方法來獲取有關此錯誤的更多資訊。

我們已經嘗試了一切來解決這個問題,但我們根本不知道它為什麼會發生…… =[

請幫我!

出現此問題是因為/etc/mime.typesCentOS 7 的文件中包含對 ascii 無效(未擴展)的字元"³"(行"application/vnd.geocube+xml g3 g³")。

為了弄清楚這一點,我必須對我的 Python 3.2.2 進行一些修改並重新載入我的應用程序。

解決方案是刪除"³"字元或任何其他無效(ascii)字元!

@邁克爾漢普頓

謝謝!

引用自:https://serverfault.com/questions/831407