我正在尝试将一些现有的Python 2代码与OpenWrt中的sysrepo
软件包绑定。 Python绑定使用SWIG与底层C / C ++进行接口。
我尝试通过调用Session.set_item()
函数来创建YANG对象,但出现异常。
但是,请注意,删除相同的YANG对象也可以。
这是一些失败的代码:
import libsysrepoPython2 as sr
def delete_configuration_ntp(session):
print('Deleting')
session.delete_item('/ietf-system:system/ntp/enabled')
print('Deleted')
def create_configuration_ntp(session, enabled):
print('Creating')
value = sr.Val(enabled, sr.SR_BOOL_T)
print(' boolean value created')
session.set_item('/ietf-system:system/ntp/enabled', value)
print(' boolean value set')
print('Created')
try:
connection = sr.Connection("example_application")
session = sr.Session(connection, sr.SR_DS_RUNNING)
subscribe = sr.Subscribe(session)
delete_configuration_ntp(session)
create_configuration_ntp(session, True)
except Exception as e:
print('Main program exception:', e)
我希望这个Python2程序能够运行,但是失败,但出现以下异常:
root@OpenWrt:~# python -V
Python 2.7.15
root@OpenWrt:~# ./minimal.py
Deleting
Deleted
Creating
boolean value created
('Main program exception:', RuntimeError('Invalid argument',))
root@OpenWrt:~#
是否有任何指针,例如如何调试SWIG?
我能否获得有关此异常原因的更多信息?