Python 从源代码构建找不到 UTF-32-BE 编码

Python built from source can't find UTF-32-BE encoding

我正在定制 linux。当我使用 requests to do some HTTP post, an import exception arised, something in idna 时。多说一句,我的系统是小端linux.

>>> from uts46data import uts46data
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
LookupError: unknown encoding: utf-32-be
>>>

我检查了如下编码。

>>> import sys
>>> sys.getdefaultencoding()
'utf-8'
>>> sys.getfilesystemencoding()
'ANSI_X3.4-1968'

我想这是一个编码问题,我该怎么办?

更多信息如下。

/ # python -c "import sys;print(sys.version)"
2.7.8 (default, Jul  7 2020, 07:25:41) 
[GCC 7.3.1 20180425]
/ # python -c "import codecs;print codecs.lookup('utf-32-be')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
LookupError: unknown encoding: utf-32-be
/ # 

自己回答。

Python 将从编码目录中定位它的编码文件。您可以从 Python 源码包中复制相应的编码文件,在 Lib/encodings 目录下。