Skip to content
Advertisement

pysftp — paramiko SSHException, Bad host key from server

I’m trying to connect to a remote host via pysftp:

JavaScript

However, I get a weird exception raised that I can’t find much detail on.

JavaScript

I found a related question that suggested I run ssh-keygen -R [host] to replace the key in my known_hosts file — once I did that, I got a new error:

JavaScript

Now, if I try to ssh to this host, it prompts me again to trust the key to be put back into my known_hosts file, which I accept and can happily ssh onto the box. After this step, if I attempt to run my script again, I get the original error Bad host key from server.

Am I doing something wrong here?

ninja edit: I should mention that the following works fine from the terminal:

JavaScript

Paramiko Debug Output:

JavaScript

Advertisement

Answer

Workaround
This seems to be some sort of bug with the pysftp wrapper… I’m not sure. Reverting to native paramiko got me connected just fine, so I’m going with that for now. Current working code:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement