Python 密码错误无法导入名称 certificate_transparency

Python Cryptography Error cannot import name certificate_transparency

尝试 运行 一个 pymodbus tcp 服务器,我得到了这个堆栈跟踪......在这里完全失去了所以任何帮助表示赞赏。谢谢!

Traceback (most recent call last):
File "Worrking_ModbusJ1939Bridge.py", line 12, in <module>
from pymodbus.server.async import StartTcpServer
File "build/bdist.linux-armv7l/egg/pymodbus/server/async.py", line 18, in <module>
File "build/bdist.linux-armv7l/egg/pymodbus/internal/ptwisted.py", line 5, in <module>
File "/usr/local/lib/python2.7/dist-packages/twisted/conch/manhole_ssh.py", line 14, in <module>
from twisted.conch.ssh import factory, session
File "/usr/local/lib/python2.7/dist-packages/twisted/conch/ssh/factory.py", line 18, in <module>
from twisted.conch.ssh import (_kex, transport, userauth, connection)
File "/usr/local/lib/python2.7/dist packages/twisted/conch/ssh/transport.py", line 345, in <module>
class SSHTransportBase(protocol.Protocol):
File "/usr/local/lib/python2.7/dist-packages/twisted/conch/ssh/transport.py", line 469, in SSHTransportBase
supportedCiphers = _getSupportedCiphers()
File "/usr/local/lib/python2.7/dist-packages/twisted/conch/ssh/transport.py", line 335, in _getSupportedCiphers
backend=default_backend(),
File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/backends/__init__.py", line 15, in default_backend
from cryptography.hazmat.backends.openssl.backend import backend
File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/backends/openssl/__init__.py", line 7, in <module>
from cryptography.hazmat.backends.openssl.backend import backend
File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/backends/openssl/backend.py", line 16, in <module>
from cryptography import utils, x509
File "/usr/local/lib/python2.7/dist-packages/cryptography/x509/__init__.py", line 7, in <module>
from cryptography.x509 import certificate_transparency
ImportError: cannot import name certificate_transparency

我在使用 pip 7 时遇到了同样的问题。升级到 pip 9 解决了它。我不确定原因。

通过:https://github.com/micheloosterhof/cowrie/issues/618

我在尝试使用 https://github.com/oracle/solaris-userland/ 构建系统为 Solaris 11.4 更新 Python 密码学时遇到了这个问题。 "simple" 对 pip 的更新对我来说不是一个选择,这不是我们做事的方式。

我最终找到了解决方案:我构建的包不正确。

密码学 2.1.4 取决于 cffi > 1.7。与我们运送的版本相比,这两个软件包都有 new 可交付位。

未能更新包清单以正确跟踪新文件导致 cffi 和加密无法导入当前版本所依赖的符号。

[非常感谢#cryptography-dev 中的 Alex Gaynor,他让我走上了解决这个问题的正确道路。

$ python2.7   
Python 2.7.14 (default, Jan 31 2018, 05:35:05) [C] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> from cryptography.hazmat.bindings._openssl import ffi, lib
>>> from cryptography.x509 import certificate_transparency
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/vendor-packages/cryptography/x509/__init__.py", line 7, in <module>
    from cryptography.x509 import certificate_transparency
ImportError: cannot import name certificate_transparency

如果您构建密码学并查看它提供的内容,您会发现实际上有一个文件(在 Solaris 上作为 /usr/lib/python-$(PYVER)/vendor-packages/cryptography/x509/certificate_transparency.py 提供)- 如果该文件不在其余部分中hierarchy 那么你最终会得到这个 ImportError。

我在 RHEL 6.7 x86_64 运行 Python 2.7.8 和旧版本的 pip (1.4.1)

上遇到了类似的问题

这是因为我一直在安装 "cp27m" 版本而不是 "cp27mu" 版本。

使用旧的 pip 1.4.1 版本,安装 cp27m 版本时不会出现问题。

而当将 pip 升级到 9.0.3 时,它吐出真正的错误...

(bmcs2)bash-4.1$ pip install cffi-1.11.5-cp27-cp27m-manylinux1_x86_64.whl cffi-1.11.5-cp27-cp27m-manylinux1_x86_64.whl 在此平台上不受支持。

(bmcs2)bash-4.1$ pip install cryptography-2.1.3-cp27-cp27m-manylinux1_x86_64.whl cryptography-2.1.3-cp27-cp27m-manylinux1_x86_64.whl 在此平台上不受支持。

"ImportError: cannot import name certificate_transparency" 已使用 "cp27mu" 版本解决。使用 "cp27mu" 构建时,pip 1.4.1 和 pip 9.0.3 版本都工作正常。

cffi-1.11.5-cp27-cp27m-manylinux1_x86_64.whl 对比 cffi-1.11.5-cp27-cp27mu-manylinux1_x86_64.whl

cryptography-2.1.3-cp27-cp27m-manylinux1_x86_64.whl 与 cryptography-2.1.3-cp27-cp27mu-manylinux1_i686.whl

更多信息在这里: https://www.python.org/dev/peps/pep-0513/#ucs-2-vs-ucs-4-builds

它对我有用(paramiko 的问题):

https://pypi.python.org/pypi/ctutlz/0.7.0

pip 安装--process-dependency-linksctutlz

我认为这更像是一个 paramiko 问题而不是 pip。在我的环境中升级 pip 没有解决这个问题,我不得不将我的 paramiko 版本降级到没有 libffi 依赖的版本,这对我有用:

pip2.7 install paramiko==1.17.0

此问题与:https://github.com/paramiko/paramiko/issues/1401

我在 AWS Lambda 中尝试 运行 Scrapy 时遇到此错误,使用 zip 文件进行部署。

我遵循了 https://www.perrygeo.com/running-python-with-compiled-code-on-aws-lambda.html 中的说明,它基本上指导您启动 Amazon Linux EC2 实例,安装要求并从中构建 zip。

设置完所有东西后,我创建的第一个包仍然给我同样的错误,但我意识到那是因为 一个隐藏文件夹.libs_cffi_backend从 zip 文件中丢失。该文件夹包含一个 .so 文件,如果不存在该文件会导致 ImportError。强行包含后,成功了。