11-27-2019 05:42 AM
Dear Community,
Can not subscribe to a netconf stream using ncclient (same code working well with NSO version 4.7).
Code:
from ncclient import manager
def start():
conn=manager.connect(host="192.168.137.235", port=2022, username="admin", password="admin", device_params={'name': "default"}, timeout=30, hostkey_verify=False, unknown_host_cb=True, look_for_keys=False)
print conn.create_subscription(stream_name="ncs-events")
while True:
print conn.take_notification().notification_xml
if __name__ == '__main__':
start()
Error:
Traceback (most recent call last):
File "stream-ncs-events.py", line 12, in <module>
start()
File "stream-ncs-events.py", line 7, in start
print conn.create_subscription(stream_name="ncs-events")
File "/usr/local/lib/python2.7/dist-packages/ncclient/manager.py", line 236, in execute
huge_tree=self._huge_tree).request(*args, **kwds)
File "/usr/local/lib/python2.7/dist-packages/ncclient/operations/subscribe.py", line 64, in request
return self._request(node)
File "/usr/local/lib/python2.7/dist-packages/ncclient/operations/rpc.py", line 349, in _request
raise self._reply.error
ncclient.operations.rpc.RPCError: {'info': '<?xml version="1.0" encoding="UTF-8"?><error-info xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><bad-element>stream</bad-element>\n</error-info>\n', 'severity': 'error', 'tag': 'unknown-element', 'path': '\n /rpc/p0:create-subscription\n ', 'message': None, 'type': 'protocol'}
stream is there:
admin@ncs# show notification stream ? Possible completions: SPWIFI SP-WIFI-stream kicker-events NCS event according to tailf-kicker.yang ncs-events NCS event according to tailf-ncs-devices.yang
Thanks in advance for your help.
Solved! Go to Solution.
11-28-2019 02:02 AM
Hello
managed to reproduce same error python 3.7 ncclient 6.6.0 and NSO 5.2.1
looking at netconf trace:
#309
<nc:rpc message-id="urn:uuid:86a933bc-510b-4be9-ace9-809af87bba52" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
<ns0:create-subscription xmlns:ns0="urn:ietf:params:xml:ns:netconf:notification:1.0">
<nc:stream>ncs-events</nc:stream>
</ns0:create-subscription>
</nc:rpc>
using netconf console (coming with NSO)
netconf-console -d --host 127.0.0.1 --port 2022 --create-subscription ncs-events
looking at netconf trace:
#266
<rpc message-id="1" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<create-subscription xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
<stream>ncs-events</stream>
</create-subscription>
</rpc>
Looks like a NS problem you can track in ncclient library to xml_.py file (sub_ele / qualify lambda that insert BASE_NS_1
I patched my library like this (ncclient/operations/subscribe.py):
53 if stream_name is not None: 54 # Original commented 55 # sub_ele(node, "stream").text = stream_name CC 56 sub_ele_ns(node, "stream", NETCONF_NOTIFICATION_NS).text = stream_name
and your script started working.
looking at netconf trace:
#311
<nc:rpc message-id="urn:uuid:6fe34aa2-7b08-4b68-8a7f-ceef96a3d986" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
<ns0:create-subscription xmlns:ns0="urn:ietf:params:xml:ns:netconf:notification:1.0">
<ns0:stream>ncs-events</ns0:stream>
</ns0:create-subscription>
</nc:rpc>
Bottom line: you can patch the library (hmmm maybe open a github issue for this ?) - or use netconf-console!
Corollary: probably you will need to do the sub_ele_ns trick for filter and start/stop times if you want to continue using ncclient
Why was it working before? maybe a less strict checking of namespaces in NSO 4.x ? (I have in mind restconf enforcing namespaces starting NSO 5.x)
Hope that helps!
11-28-2019 02:02 AM
Hello
managed to reproduce same error python 3.7 ncclient 6.6.0 and NSO 5.2.1
looking at netconf trace:
#309
<nc:rpc message-id="urn:uuid:86a933bc-510b-4be9-ace9-809af87bba52" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
<ns0:create-subscription xmlns:ns0="urn:ietf:params:xml:ns:netconf:notification:1.0">
<nc:stream>ncs-events</nc:stream>
</ns0:create-subscription>
</nc:rpc>
using netconf console (coming with NSO)
netconf-console -d --host 127.0.0.1 --port 2022 --create-subscription ncs-events
looking at netconf trace:
#266
<rpc message-id="1" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<create-subscription xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
<stream>ncs-events</stream>
</create-subscription>
</rpc>
Looks like a NS problem you can track in ncclient library to xml_.py file (sub_ele / qualify lambda that insert BASE_NS_1
I patched my library like this (ncclient/operations/subscribe.py):
53 if stream_name is not None: 54 # Original commented 55 # sub_ele(node, "stream").text = stream_name CC 56 sub_ele_ns(node, "stream", NETCONF_NOTIFICATION_NS).text = stream_name
and your script started working.
looking at netconf trace:
#311
<nc:rpc message-id="urn:uuid:6fe34aa2-7b08-4b68-8a7f-ceef96a3d986" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
<ns0:create-subscription xmlns:ns0="urn:ietf:params:xml:ns:netconf:notification:1.0">
<ns0:stream>ncs-events</ns0:stream>
</ns0:create-subscription>
</nc:rpc>
Bottom line: you can patch the library (hmmm maybe open a github issue for this ?) - or use netconf-console!
Corollary: probably you will need to do the sub_ele_ns trick for filter and start/stop times if you want to continue using ncclient
Why was it working before? maybe a less strict checking of namespaces in NSO 4.x ? (I have in mind restconf enforcing namespaces starting NSO 5.x)
Hope that helps!
11-28-2019 03:59 AM
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide