python - 在 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
解决方案
推荐阅读
- json - 解组 JSON 映射,其中键是非内置类型
- c++ - C++ Curl 无法使用 SSL_CTX_FUNCTION 的 LetsEncrypt pem 文件进行连接
- java - 如何在 j00q 中引用 Postgres 约束?
- mongodb - 如何在 ubuntu 15.10 上安装 Mongodb 4
- python - Python 中的效率:a = array[x][y] vs array[x][y]
- binary - 八度四舍五入和评估顺序
- excel - VBA PivotTable 和 PivotField - PivotField.CurrentPage 未更新
- c++ - boost::program_options: 是否可以将一个选项设置为另一个选项的默认值?
- php - 未定义的属性:stdClass - LARAVEL
- php - 如何修复(Curl PHP)中不允许的 405