hi expert
I have a question when i using pyez
here is my code
from jnpr.junos import Device
from pprint import pprint
def get_ospf_neighbor_information(username, pwd, host ):
dev = Device(host=host, user=username, password=pwd)
dev.open()
rpc = dev.rpc.get_ospf_neighbor_information({'format':'json'})
dev.close()
return rpc
if __name__ == "__main__":
ospf_r1 = get_ospf_neighbor_information('lab', 'lab123', '172.27.0.22' )
pprint(ospf_r1)
the code is work but if i change json format by this cli
export-format state-data json compact
system will report this error
---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
File ~/anaconda3/lib/python3.11/site-packages/jnpr/junos/device.py:878, in _Connection.execute(self, rpc_cmd, ignore_warning, **kvargs)
877 try:
--> 878 return json.loads(rpc_rsp_e.text, strict=False)
879 except ValueError as ex:
880 # when data is {}{.*} types
File ~/anaconda3/lib/python3.11/json/__init__.py:359, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
358 kw['parse_constant'] = parse_constant
--> 359 return cls(**kw).decode(s)
File ~/anaconda3/lib/python3.11/json/decoder.py:337, in JSONDecoder.decode(self, s, _w)
333 """Return the Python representation of ``s`` (a ``str`` instance
334 containing a JSON document).
335
336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()
File ~/anaconda3/lib/python3.11/json/decoder.py:353, in JSONDecoder.raw_decode(self, s, idx)
352 try:
--> 353 obj, end = self.scan_once(s, idx)
354 except StopIteration as err:
JSONDecodeError: Expecting property name enclosed in double quotes: line 14 column 9 (char 355)
During handling of the above exception, another exception occurred:
JSONLoadError Traceback (most recent call last)
Cell In[1], line 14
9 return rpc
12 if __name__ == "__main__":
---> 14 ospf_r1 = get_ospf_neighbor_information('lab', 'lab123', '172.27.100.93' )
15 pprint(ospf_r1)
Cell In[1], line 7, in get_ospf_neighbor_information(username, pwd, host)
5 dev = Device(host=host, user=username, password=pwd)
6 dev.open()
----> 7 rpc = dev.rpc.get_ospf_neighbor_information({'format':'json'})
8 dev.close()
9 return rpc
File ~/anaconda3/lib/python3.11/site-packages/jnpr/junos/rpcmeta.py:363, in _RpcMetaExec.__getattr__.<locals>._exec_rpc(*vargs, **kvargs)
358 rpc.attrib[k] = v
360 # now invoke the command against the
361 # associated :junos: device and return
362 # the results per :junos:execute()
--> 363 return self._junos.execute(rpc, **dec_args)
File ~/anaconda3/lib/python3.11/site-packages/jnpr/junos/decorators.py:76, in normalizeDecorator.<locals>.wrapper(*args, **kwargs)
74 else:
75 try:
---> 76 return function(*args, **kwargs)
77 except Exception:
78 raise
File ~/anaconda3/lib/python3.11/site-packages/jnpr/junos/decorators.py:31, in timeoutDecorator.<locals>.wrapper(*args, **kwargs)
29 else:
30 try:
---> 31 return function(*args, **kwargs)
32 except Exception:
33 raise
File ~/anaconda3/lib/python3.11/site-packages/jnpr/junos/device.py:884, in _Connection.execute(self, rpc_cmd, ignore_warning, **kvargs)
882 return json.loads(re.sub(r"\s?{\s?}\s?", "", rpc_rsp_e.text))
883 else:
--> 884 raise JSONLoadError(ex, rpc_rsp_e.text)
885 else:
886 warnings.warn(
887 "Native JSON support is only from 14.2 onwards", RuntimeWarning
888 )
JSONLoadError: JSONLoadError(reason: Expecting property name enclosed in double quotes: line 14 column 9 (char 355),
The offending config appears to be:
12: "activity-timer" : "36"
13: },
14: {
15: "neighbor-address" : "12.0.0.2",
16: "interface-name" : "ge-0/0/2.0",
)
I am not sure how to change that ,but old json format is so difficult to read