gpt4 book ai didi

python - Paramiko TypeError:from_buffer()无法返回str或unicode或bytearray对象内的原始字符串的地址

转载 作者:行者123 更新时间:2023-12-02 14:26:32 25 4
gpt4 key购买 nike

我正在尝试使用Python和Paramiko连接到SFTP服务器,但出现此错误(当我使用pysftp时会发生相同的错误):

starting thread (client mode): 0x17ccde50L
Local version/idstring: SSH-2.0-paramiko_2.7.2
Remote version/idstring: SSH-2.0-OpenSSH_7.2
Connected (version 2.0, client OpenSSH_7.2)
kex algos:[u'curve25519-sha256@libssh.org', u'ecdh-sha2-nistp256', u'ecdh-sha2-nistp384', u'ecdh-sha2-nistp521', u'diffie-hellman-group-exchange-sha256', u'diffie-hellman-group14-sha1'] server key:[u'ssh-rsa', u'rsa-sha2-512', u'rsa-sha2-256', u'ssh-dss', u'ecdsa-sha2-nistp256', u'ssh-ed25519'] client encrypt:[u'chacha20-poly1305@openssh.com', u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'aes128-gcm@openssh.com', u'aes256-gcm@openssh.com'] server encrypt:[u'chacha20-poly1305@openssh.com', u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'aes128-gcm@openssh.com', u'aes256-gcm@openssh.com'] client mac:[u'umac-64-etm@openssh.com', u'umac-128-etm@openssh.com', u'hmac-sha2-256-etm@openssh.com', u'hmac-sha2-512-etm@openssh.com', u'hmac-sha1-etm@openssh.com', u'umac-64@openssh.com', u'umac-128@openssh.com', u'hmac-sha2-256', u'hmac-sha2-512', u'hmac-sha1'] server mac:[u'umac-64-etm@openssh.com', u'umac-128-etm@openssh.com', u'hmac-sha2-256-etm@openssh.com', u'hmac-sha2-512-etm@openssh.com', u'hmac-sha1-etm@openssh.com', u'umac-64@openssh.com', u'umac-128@openssh.com', u'hmac-sha2-256', u'hmac-sha2-512', u'hmac-sha1'] client compress:[u'none', u'zlib@openssh.com'] server compress:[u'none', u'zlib@openssh.com'] client lang:[u''] server lang:[u''] kex follows?False
Kex agreed: curve25519-sha256@libssh.org
HostKey agreed: ssh-ed25519
Cipher agreed: aes128-ctr
MAC agreed: hmac-sha2-256
Compression agreed: none
kex engine KexCurve25519 specified hash_algo <built-in function openssl_sha256>
Unknown exception: from_buffer() cannot return the address of the raw string within a str or unicode or bytearray object
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/paramiko/transport.py", line 2075, in run
self.kex_engine.parse_next(ptype, m)
File "/usr/lib/python2.7/site-packages/paramiko/kex_curve25519.py", line 64, in parse_next
return self._parse_kexecdh_reply(m)
File "/usr/lib/python2.7/site-packages/paramiko/kex_curve25519.py", line 129, in _parse_kexecdh_reply
self.transport._activate_outbound()
File "/usr/lib/python2.7/site-packages/paramiko/transport.py", line 2553, in _activate_outbound
self.local_cipher, key_out, IV_out, self._ENCRYPT
File "/usr/lib/python2.7/site-packages/paramiko/transport.py", line 1934, in _get_cipher
return cipher.encryptor()
File "/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/ciphers/base.py", line 126, in encryptor
self.algorithm, self.mode
File "/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 487, in create_symmetric_encryption_ctx
return _CipherContext(self, cipher, mode, _CipherContext._ENCRYPT)
File "/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/openssl/ciphers.py", line 69, in __init__
iv_nonce = self._backend._ffi.from_buffer(mode.nonce)
TypeError: from_buffer() cannot return the address of the raw string within a str or unicode or bytearray object
我能够使用以下方法成功连接到SFTP服务器:
sftp -oPort=22 xxxxx@10.132.x.x:/home
所以我知道服务器存在并且可以访问。
我在Python中的代码就是这样:
paramiko.util.log_to_file("filename.log")
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(
paramiko.AutoAddPolicy())
ssh.connect(ftp_host, username=ftp_username, password=ftp_password, timeout=None)
还有一些依赖
asn1crypto @ file:///home/folder/app/utils/asn1crypto-1.2.0-py2.py3-none-any.whl
bcrypt @ file:///home/folder/app/utils/bcrypt-3.1.6-cp27-cp27mu-manylinux1_x86_64.whl
cffi==1.5.2
cryptography @ file:///home/folder/app/utils/cryptography-3.1-cp27-cp27mu-manylinux2010_x86_64.whl
netmiko==2.3.2
paramiko @ file:///home/folder/app/utils/vendor/paramiko-2.7.2-py2.py3-none-any.whl
ply==3.4
pyasn1==0.1.9
pycparser==2.19
PyNaCl @ file:///home/folder/app/utils/PyNaCl-1.3.0-cp27-cp27mu-manylinux1_x86_64.whl
pyOpenSSL==16.0.0
six==1.9.0
我的问题是,该错误的确切含义是什么?解决该错误的最佳方法是什么?我需要将图像复制到SFTP,但无法完全连接。
顺便说一句,我正在运行Python的服务器卡在2.7上,并且我不允许对其进行升级。另外,它无法访问互联网,所以我不能使用apt-get之类的东西。我通过拖放压缩文件夹或.whl文件来安装东西。我只是找到依赖关系的正确组合而已。

最佳答案

本主题建议您可能具有过时的依赖关系:
https://github.com/paramiko/paramiko/issues/1027
The solution by @bieli似乎可以帮助许多面临此问题的人:

sudo pip uninstall cryptography -y && sudo apt-get purge python3-cryptography && sudo apt-get autoremove && sudo pip3 install --upgrade cryptography

如果无法升级依赖项,则可以尝试使用其他KEX。但是总的来说,这可能是死路一条。

强制性警告:请勿使用 AutoAddPolicy –这样做会丢失针对 MITM attacks的保护。有关正确的解决方案,请参见 Paramiko "Unknown Server"

关于python - Paramiko TypeError:from_buffer()无法返回str或unicode或bytearray对象内的原始字符串的地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63709660/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com