Unexpected session close error is thrown when connecting netconf

2.8k views Asked by At

I am using ncclient to connect to the netconf. However when ever i try to connect through python

"ncclient.transport.errors.SessionCloseError: Unexpected session close" error is thrown. the code snippet that i am using is given below

manager.connect('<servername>',22,username='<username>')

Any help on this is much appriciated. I am able to connect to the remote server by using public key, hence i didnt provide passwordk in connect

And in the netconf server logs i am able to see access-denied error. (I got the same prob even when i tried with username and pwd)

2

There are 2 answers

0
Andrew Stone On

its possible that your machines don't know each other (like when you connect via normal ssh and get the "unknown key, really connect (y/n)?" error. In that case, by default the session will not connect. To change this behavior use the "unknown_host_cb" parameter:

def allowUnknownHosts(host,fingerprint):
  return True

self.manager = manager.connect(host=host, port=port, username=user,password=password, unknown_host_cb=allowUnknownHosts)
0
John Jensen On

You haven't given a lot of information.

  1. Which version of ncclient are you using?
  2. Which version of Python are you using?
  3. Which NETCONF implementation are you trying to connect to? Is this to an actual switch or router, or something like a Linux server running libnetconf or yuma?

Based on the info here, I could imagine a couple of things being wrong:

  • paramiko isn't using the right key to establish SSH transport.
  • You're attempting to establish a NETCONF session with an SSH server rather than a NETCONF server.

In your script, create some logs with something like manager.logging.basicConfig(filename='ncclient.log', level=manager.logging.DEBUG) and then re-run your script - do you get anything more informative?

This is an old question, but I hope I can point you in the right direction at least.