2

I am trying to use pysftp and gets the same error as many others. That there is no hostkey for host. I have tried many fixes, but none of them seem to work.

When I try to set hostname I get these errors:

cnopts = pysftp.CnOpts()
cnopts.hostkeys.load('known_hosts')

with pysftp.Connection(host, username, password, cnopts=cnopts) as sftp:
/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/pysftp/__init__.py:61: UserWarning: Failed to load HostKeys from /home/runner/.ssh/known_hosts.  You will need to explicitly load HostKeys (cnopts.hostkeys.load(filename)) or disableHostKey checking (cnopts.hostkeys = None).
  warnings.warn(wmsg, UserWarning)

I have also tried to turn off hostkey, and load locally, but nothing seems to work.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Magne Moe
  • 21
  • 2

1 Answers1

0

You get that warning, if known_hosts does not exist in the default location and you do not specify an alternative location in CnOpts constructor.

This should work:

cnopts = pysftp.CnOpts(knownhosts='known_hosts')
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992