简单的 pysFTP 昨晚工作,但现在不工作

Simple pysFTP was working last night, but now does not

昨晚我在写我的第一个 pySFTP Notebook,我能够让它工作。我睡觉时它在工作,但现在不工作了。我收到连接命令错误....

import pysftp
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None    # disable host key checking.
#with pysftp.Connection('test.rebex.net', username='demo',password='password', cnopts=cnopts) as sftp:
# do stuff here
#  print('this works!')


s = pysftp.Connection(host='test.rebex.net', username='demo', password='password', cnopts=cnopts) 
data = s.listdir() 
s.close() 
for i in data: 
    print (i)

我收到的错误是...

Unknown exception: from_buffer() cannot return the address of the raw string within a bytes or unicode object
Traceback (most recent call last):
  File "/databricks/python/lib/python3.5/site-packages/paramiko/transport.py", line 2075, in run
    self.kex_engine.parse_next(ptype, m)
  File "/databricks/python/lib/python3.5/site-packages/paramiko/kex_curve25519.py", line 64, in parse_next
    return self._parse_kexecdh_reply(m)
  File "/databricks/python/lib/python3.5/site-packages/paramiko/kex_curve25519.py", line 129, in _parse_kexecdh_reply
    self.transport._activate_outbound()
  File "/databricks/python/lib/python3.5/site-packages/paramiko/transport.py", line 2553, in _activate_outbound
    self.local_cipher, key_out, IV_out, self._ENCRYPT
  File "/databricks/python/lib/python3.5/site-packages/paramiko/transport.py", line 1934, in _get_cipher
    return cipher.encryptor()
  File "/databricks/python/lib/python3.5/site-packages/cryptography/hazmat/primitives/ciphers/base.py", line 121, in encryptor
    self.algorithm, self.mode
  File "/databricks/python/lib/python3.5/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 298, in create_symmetric_encryption_ctx
    return _CipherContext(self, cipher, mode, _CipherContext._ENCRYPT)
  File "/databricks/python/lib/python3.5/site-packages/cryptography/hazmat/backends/openssl/ciphers.py", line 67, in __init__
    iv_nonce = self._backend._ffi.from_buffer(mode.nonce)
TypeError: from_buffer() cannot return the address of the raw string within a bytes or unicode object

TypeError: from_buffer() cannot return the address of the raw string within a bytes or unicode object

感谢您的帮助!

pysftpparamiko 列为 one of its dependencies. Paramiko issue #1037 文档,并将代码中抛出的错误归因于与 cryptography 的版本兼容性问题。

我为避免这种情况提出的建议包括以下内容:

  1. 使用 Databricks Conda Runtime 改进 Python 依赖管理和可见性
  2. 升级密码版本(我用cryptography=2.6.1测试过,它包含在databricks-standard conda env中)