pyasn1引发错误:pyasn1错误(组件类型错误%r vs %r)

2024-06-25 23:41:38 发布

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

我只有一个选择,在这个选择中,我只想用一个字段传递类的对象。在

这是我的密码片段:-在

from pyasn1.type import univ, namedtype, tag, char, namedval, useful
from pyasn1.codec.ber import encoder

class MiepPullWtdr(univ.Sequence):
    componentType = namedtype.NamedTypes(namedtype.NamedType('wtdrId', univ.Integer().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))))

class ChoiceData(univ.Choice):
    componentType = namedtype.NamedTypes(namedtype.NamedType('miepPullWtdr', MiepPullWtdr().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))))

seqObj = MiepPullWtdr()
seqObj.setComponentByName('wtdrId', 6555)
choiceObj = ChoiceData()
choiceObj.setComponentByName('miepPullWtdr', seqObj)

当我运行脚本时测试.py,它抛出这个错误:-在

^{pr2}$

有什么帮助吗?谢谢。在


Tags: fromimporttagclassunivpyasn1subtypenamedtype
1条回答
网友
1楼 · 发布于 2024-06-25 23:41:38

MiepPullWtdr类型如何在其独立定义中标记为ASN.1与作为ChoiceData组件的方式存在不一致。我不知道你的意图是什么,这里有可能是许多一致的版本之一:

from pyasn1.type import univ, namedtype, tag

class MiepPullWtdr(univ.Sequence):
    tagSet = univ.Sequence.tagSet.tagImplicitly(
        tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0)
    )
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('wtdrId', univ.Integer().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0)))
    )

class ChoiceData(univ.Choice):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('miepPullWtdr', MiepPullWtdr())
    )

seqObj = MiepPullWtdr()
seqObj['wtdrId'] = 6555
choiceObj = ChoiceData()
choiceObj['miepPullWtdr'] = seqObj

print(choiceObj.prettyPrint())

相关问题 更多 >