我在 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'
我是一名优秀的程序员,十分优秀!