在pysftp中建立连接字符串时出现不一致的错误

时间:2019-07-30 14:28:24

标签: python pyspark pysftp

我正在尝试在SFTP服务器上的特定目录中构建文件列表,并捕获所述文件的某些属性。连接到服务器时出现不一致的问题,但我一直找不到解决方案。我说这个问题是不一致的,因为我可以一分钟运行我的Databricks笔记本,让它返回此特定错误,但是几分钟后再运行它,并成功完成它,而完全不对笔记本进行任何更改。

from base64 import decodebytes
import paramiko
import pysftp

keydata=b"""host key here"""
key = paramiko.RSAKey(data=decodebytes(keydata))

cnopts = pysftp.CnOpts()
cnopts.hostkeys.add('123.456.7.890', 'ssh-rsa', key)

hostname = "123.456.7.890"
user = "username"
pw = "password"

with pysftp.Connection(host=hostname, username=user, password=pw, cnopts=cnopts) as sftp:
    * actions once the connection has been established *

我收到以下错误消息(当它确实出错时),并且将我建立SFTP连接的罪魁祸首标记为代码的最后一行。我无法按需重现此错误。就像我说的那样,即使我在两次运行之间都没有对代码进行任何更改,有时代码也可以正常运行,而有时返回以下错误。

Unknown exception: from_buffer() cannot return the address of the raw string within a bytes or unicode object
Traceback (most recent call last):
  File "/local_disk0/pythonVirtualEnvDirs/virtualEnv-a488e5a9-de49-48a7-b684-893822004827/lib/python3.5/site-packages/paramiko/transport.py", line 2075, in run
    self.kex_engine.parse_next(ptype, m)
  File "/local_disk0/pythonVirtualEnvDirs/virtualEnv-a488e5a9-de49-48a7-b684-893822004827/lib/python3.5/site-packages/paramiko/kex_curve25519.py", line 64, in parse_next
    return self._parse_kexecdh_reply(m)
  File "/local_disk0/pythonVirtualEnvDirs/virtualEnv-a488e5a9-de49-48a7-b684-893822004827/lib/python3.5/site-packages/paramiko/kex_curve25519.py", line 128, in _parse_kexecdh_reply
    self.transport._verify_key(peer_host_key_bytes, sig)
  File "/local_disk0/pythonVirtualEnvDirs/virtualEnv-a488e5a9-de49-48a7-b684-893822004827/lib/python3.5/site-packages/paramiko/transport.py", line 1886, in _verify_key
    if not key.verify_ssh_sig(self.H, Message(sig)):
  File "/local_disk0/pythonVirtualEnvDirs/virtualEnv-a488e5a9-de49-48a7-b684-893822004827/lib/python3.5/site-packages/paramiko/rsakey.py", line 134, in verify_ssh_sig
    msg.get_binary(), data, padding.PKCS1v15(), hashes.SHA1()
  File "/local_disk0/pythonVirtualEnvDirs/virtualEnv-a488e5a9-de49-48a7-b684-893822004827/lib/python3.5/site-packages/cryptography/hazmat/backends/openssl/rsa.py", line 474, in verify
    self._backend, data, algorithm
  File "/local_disk0/pythonVirtualEnvDirs/virtualEnv-a488e5a9-de49-48a7-b684-893822004827/lib/python3.5/site-packages/cryptography/hazmat/backends/openssl/utils.py", line 41, in _calculate_digest_and_algorithm
    hash_ctx.update(data)
  File "/local_disk0/pythonVirtualEnvDirs/virtualEnv-a488e5a9-de49-48a7-b684-893822004827/lib/python3.5/site-packages/cryptography/hazmat/primitives/hashes.py", line 93, in update
    self._ctx.update(data)
  File "/local_disk0/pythonVirtualEnvDirs/virtualEnv-a488e5a9-de49-48a7-b684-893822004827/lib/python3.5/site-packages/cryptography/hazmat/backends/openssl/hashes.py", line 50, in update
    data_ptr = self._backend._ffi.from_buffer(data)
TypeError: from_buffer() cannot return the address of the raw string within a bytes or unicode object

0 个答案:

没有答案