Python绑定到sysrepo时出现无效参数异常

2024-04-25 08:39:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用OpenWrt中的sysrepo包绑定一些现有的python2代码。Python绑定使用SWIG与底层C/C++进行接口。你知道吗

我试图通过调用Session.set_item()函数来创建一个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?你知道吗

关于这个例外的原因,我能得到更多的信息吗?你知道吗


Tags: 代码valuesessionenabledrootitemdeletesystem