Python Pysftp Error

后端 未结 2 1701
既然无缘
既然无缘 2020-12-31 23:45

My code:

import pysftp 
s = pysftp.Connection(host=\'test.rebex.net\', username=\'demo\', password=\'password\') 
data = s.listdir() 
s.close() 
for i in dat         


        
相关标签:
2条回答
  • 2021-01-01 00:18

    That initial error appears to be a problem connecting with the remote server (SSHException). The second (AttributeError), is from a bug in the code that occurs when the connection fails. It is fixed in the latest version of pysftp

    https://pypi.python.org/pypi/pysftp

    pip install -U pysftp
    

    is your friend.

    0 讨论(0)
  • 2021-01-01 00:41

    updating the package didn't work for me, as it was already up-to-date (latest for python 2.7 at least)

    Found a better aproach here.

    1) You can manualy add the ssh key to the known_hosts file

    ssh test.rebex.net
    

    2) Or you can set a flag to ignore it

    import pysftp
    cnopts = pysftp.CnOpts()
    cnopts.hostkeys = None    # disable host key checking.
    with pysftp.Connection('host', username='me',private_key=private_key,
                               private_key_pass=private_key_password,
                               cnopts=cnopts) as sftp
        # do stuff here
    
    0 讨论(0)
提交回复
热议问题