我在DigitalOcean上运行Ubuntu 18.04 Droplet,需要设置它们之间的文件传输。

Pysftp / Paramiko库非常适合这项工作,但是在建立连接时遇到了麻烦。从桌面使用相同的代码连接效果很好。

cnopts = pysftp.CnOpts()
cnopts.hostkeys = None

with pysftp.Connection(host='ip adress',  username='username',
                       password='pass', cnopts=cnopts) as sftp:


初始化连接时的错误消息是:

Traceback (most recent call last):
  File "/home/airflow/airflow/tasks/ta_auto/screener_slave.py", line 315, in <module>
    cnopts = pysftp.CnOpts()#knownhosts='/home/airflow/.ssh/known_hosts')
  File "/home/airflow/pipeline/lib/python3.6/site-packages/pysftp/__init__.py", line 54, in __init__
    self.hostkeys.load(knownhosts)
  File "/home/airflow/pipeline/lib/python3.6/site-packages/paramiko/hostkeys.py", line 101, in load
    e = HostKeyEntry.from_line(line, lineno)
  File "/home/airflow/pipeline/lib/python3.6/site-packages/paramiko/hostkeys.py", line 364, in from_line
    key = ECDSAKey(data=decodebytes(key), validate_point=False)
  File "/home/airflow/pipeline/lib/python3.6/site-packages/paramiko/ecdsakey.py", line 163, in __init__
    key = ec.EllipticCurvePublicKey.from_encoded_point(
AttributeError: type object 'EllipticCurvePublicKey' has no attribute 'from_encoded_point'

最佳答案

截至目前,升级到Paramiko的最新版本– 2.6。

这很可能是与以下问题相同的问题:
 How to silence EllipticCurvePublicNumbers.encode_point CryptographyDeprecationWarning when using Paramiko in Python



强制性警告:请勿设置cnopts.hostkeys = None,除非您不关心安全性。有关正确的解决方案,请参见Verify host key with pysftp

关于python - pysftp/Paramiko中的“类型对象'EllipticCurvePublicKey'没有属性'from_encoded_point'”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58145188/

10-13 09:19