首页 > 解决方案 > Python 绑定到 sysrepo 给出了无效的参数异常

问题描述

我正在尝试将一些现有的 Python 2 代码与sysrepoOpenWrt 中的包绑定。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?

我可以获得有关此异常原因的更多信息吗?

标签: pythonswigopenwrtietf-netmod-yangietf-netconf

解决方案


推荐阅读