python的paramiko load_system_host_keys()引发AttributeError:“ int”对象没有属性“ value”(加密)

时间:2018-09-27 07:37:22

标签: python ssh paramiko

此问题出现在paramiko v2(2.4.2)中,而不是出现在paramiko v1(1.18.5)中。

密钥存储在known_hosts文件中。

我正在使用以下代码

import paramiko

ssh_client = paramiko.SSHClient()
ssh_client.load_system_host_keys()
ssh_client.connect(hostname='hostname', username='user', password='pass')

load_system_host_keys()失败,并且我得到此回溯:

Traceback (most recent call last):
  File "/snap/pycharm-community/85/helpers/pydev/pydevd.py", line 1664, in <module>
    main()
  File "/snap/pycharm-community/85/helpers/pydev/pydevd.py", line 1658, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/snap/pycharm-community/85/helpers/pydev/pydevd.py", line 1068, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/administrator/rs_autolabs/utils/test.py", line 9, in <module>
    ssh_client.load_system_host_keys()
  File "/usr/local/lib/python2.7/dist-packages/paramiko/client.py", line 104, in load_system_host_keys
    self._system_host_keys.load(filename)
  File "/usr/local/lib/python2.7/dist-packages/paramiko/hostkeys.py", line 97, in load
    e = HostKeyEntry.from_line(line, lineno)
  File "/usr/local/lib/python2.7/dist-packages/paramiko/hostkeys.py", line 356, in from_line
    key = RSAKey(data=decodebytes(key))
  File "/usr/local/lib/python2.7/dist-packages/paramiko/rsakey.py", line 69, in __init__
    ).public_key(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 8, in <module>
    from cryptography.x509.base import (
  File "/usr/local/lib/python2.7/dist-packages/cryptography/x509/base.py", line 16, in <module>
    from cryptography.x509.extensions import Extension, ExtensionType
  File "/usr/local/lib/python2.7/dist-packages/cryptography/x509/extensions.py", line 24, in <module>
    from cryptography.x509.general_name import GeneralName, IPAddress, OtherName
  File "/usr/local/lib/python2.7/dist-packages/cryptography/x509/general_name.py", line 18, in <module>
    from cryptography.x509.name import Name
  File "/usr/local/lib/python2.7/dist-packages/cryptography/x509/name.py", line 28, in <module>
    _ASN1_TYPE_TO_ENUM = dict((i.value, i) for i in _ASN1Type)
  File "/usr/local/lib/python2.7/dist-packages/cryptography/x509/name.py", line 28, in <genexpr>
    _ASN1_TYPE_TO_ENUM = dict((i.value, i) for i in _ASN1Type)
AttributeError: 'int' object has no attribute 'value'

1 个答案:

答案 0 :(得分:0)

解决方案是enum模块的问题。 加密使用enum34。 我有自己的实现要在与我的代码相同的程序包中的“ enum.py”文件中进行枚举。 密码学尝试使用此模块代替enum34。 将我的“ enum.py”文件扩孔到其他东西就解决了。

在这里阅读: python's cryptography throwing AttributeError: 'int' object has no attribute 'value'