python3.2-错误:root:未找到哈希 md5 的代码

python3.2-错误:root:未找到哈希 md5 的代码

我们有一个遗留应用程序,它需要 Python 版本 3.2 才能运行. 因此我们编译并安装Python 版本 3.2。

我们能够成功编译并安装 3.2 版 PythonUbuntu 20.04.1 LTS,但我们开始遇到问题使用Python“hashlib”库正如下面的摘录所示……

root@sinj:/usr/local/src/lbginst# /usr/local/lb/py32/bin/python3.2 -c "import hashlib;m=hashlib.md5();print(m.hexdigest())"
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
  File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 141, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 91, in __get_builtin_constructor
    raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type md5
ERROR:root:code for hash sha1 was not found.
Traceback (most recent call last):
  File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 141, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 91, in __get_builtin_constructor
    raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha1
ERROR:root:code for hash sha224 was not found.
Traceback (most recent call last):
  File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 141, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 91, in __get_builtin_constructor
    raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha224
ERROR:root:code for hash sha256 was not found.
Traceback (most recent call last):
  File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 141, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 91, in __get_builtin_constructor
    raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha256
ERROR:root:code for hash sha384 was not found.
Traceback (most recent call last):
  File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 141, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 91, in __get_builtin_constructor
    raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha384
ERROR:root:code for hash sha512 was not found.
Traceback (most recent call last):
  File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 141, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/local/lb/py32/lib/python3.2/hashlib.py", line 91, in __get_builtin_constructor
    raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha512
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'md5'

问题:我们怎样才能解决所提出的问题?

注一:在查阅了互联网上的数十个来源后,我们开始怀疑与库文件 加密库二进制文件。
注二:我们也非常欢迎有关如何诊断正在发生的事情的信息!

谢谢!=D


更新:另一个症状是在构建过程中出现此消息(makemake install)...

Failed to build these modules:
_hashlib           _ssl   

答案1

您的问题是您正在使用 OpenSSL 1.1 和不支持该版本 OpenSSL 的旧版 Python。Python 3.2 于 2011 年发布,OpenSSL 1.1.0 于 2016 年发布。

由于 OpenSSL 1.0 不再受安全支持,您需要将使用的 Python 版本升级到合适的版本。如果您等不及并计划在未来三个月内升级,您也可以使用 Ubuntu 16.04 容器,其中包含 OpenSSL 1.0,Ubuntu 将支持该版本到四月。但是,Python 3.2 也可能存在未修补的漏洞。

答案2

出现所指出的问题是因为 python 版本 3.2 与 openssl 版本 1.1 不兼容,而后者是apt-getUbuntu 20.04.1 LTS 使用的标准版本 ()。

解决方案是编译并安装(makemake install)openssl 1.0版本,并使用变量“CFLAGS”和“LDFLAGS”配置编译过程,以便它使用openssl 1.0版本。

# NOTE: Download, compile and install openssl. By Questor
cd /usr/local/src
wget https://www.openssl.org/source/old/1.0.2/openssl-1.0.2k.tar.gz
tar -zxvf openssl-1.0.2k.tar.gz
cd ./openssl-1.0.2k
./config -fPIC shared
make && make install
cd ..
rm -rf ./openssl-1.0.2k

# NOTE: Download, compile and install Python 3.2. By Questor
cd /usr/local/src
wget https://www.python.org/ftp/python/3.2.2/Python-3.2.2.tgz
tar -zxvf Python-3.2.2.tgz
cd ./Python-3.2.2

eval "./configure --with-threads --enable-shared CFLAGS='-I/usr/local/ssl/include/openssl/ -I/usr/local/ssl/include/' LDFLAGS='-L/usr/local/lib/ -L/usr/local/ssl/lib/ -Wl,-rpath,/usr/local/lib/ -Wl,-rpath,/usr/local/ssl/lib/'"
make && make install
cd ..
rm -rf ./Python-3.2.2

# NOTE: Test python3.2 using "_hashlib" and "_ssl" resources. By Questor
/usr/local/bin/python3.2 -c "import hashlib;m=hashlib.md5();print(m.hexdigest())"

完成!谢谢!=D

[参考文献:https://chowyi.com/%E6%BA%90%E7%A0%81%E7%BC%96%E8%AF%91%E5%AE%89%E8%A3%85Python3%E5%8F%8A%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3/,https://raspberrypi.stackexchange.com/questions/66782/how-to-install-openssl-1-0-2-on-raspberry-pi3/66788?newreg=89c76bb5b1f542f88a63268243455e75, https://stackoverflow.com/questions/1904990/ld-library-path-and-l-at-link-time 之间的区别是什么/1905144#1905144,https://stackoverflow.com/questions/22409092/coredump-when-compiling-python-with-a-custom-openssl-version/22409394#22409394,https://stackoverflow.com/questions/5937337/building-python-with-ssl-support-in-non-standard-location/5939170#5939170,https://stackoverflow.com/questions/2537271/compile-openssl-with-the-shared-option/23513969#23513969, https://www.hpc.dtu.dk/?page_id=1180, https://stackoverflow.com/a/24026737/3223785, https://www.a2hosting.com/kb/security/ssl/determining-the-openssl-version, https://superuser.com/a/1618761/195840, https://stackoverflow.com/a/46476640/3223785]

相关内容