[Pyasn1]: 引发错误.PyAsn1Error('Component type error %r vs %r' % (t, value))
[Pyasn1]: raise error.PyAsn1Error('Component type error %r vs %r' % (t, value))
我只有一个选择,在那个选择中,我想只用一个字段传递 class 的对象。
这是我的代码片段:-
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)
当我 运行 我的脚本 test.py 时,它抛出这个错误:-
Traceback (most recent call last):
File "test.py", line 18, in <module>
choiceObj.setComponentByName('miepPullWtdr', seqObj)
File "/data/aman/cdr/lib/pyasn1-0.1.7/pyasn1/type/univ.py", line 760, in setComponentByName verifyConstraints
File "/data/aman/cdr/lib/pyasn1-0.1.7/pyasn1/type/univ.py", line 979, in setComponentByPosition
self._verifyComponent(idx, value)
File "/data/aman/cdr/lib/pyasn1-0.1.7/pyasn1/type/univ.py", line 751, in _verifyComponent
raise error.PyAsn1Error('Component type error %r vs %r' % (t, value))
pyasn1.error.PyAsn1Error: Component type error MiepPullWtdr() vs MiepPullWtdr().setComponentByPosition(0, Integer(6555))
有什么帮助吗?谢谢
MiepPullWtdr
类型在其独立定义中与作为 ChoiceData
组件的 ASN.1 标记方式存在不一致。我不确定你的意图到底是什么,这里可能是许多一致版本之一:
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())
我只有一个选择,在那个选择中,我想只用一个字段传递 class 的对象。
这是我的代码片段:-
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)
当我 运行 我的脚本 test.py 时,它抛出这个错误:-
Traceback (most recent call last):
File "test.py", line 18, in <module>
choiceObj.setComponentByName('miepPullWtdr', seqObj)
File "/data/aman/cdr/lib/pyasn1-0.1.7/pyasn1/type/univ.py", line 760, in setComponentByName verifyConstraints
File "/data/aman/cdr/lib/pyasn1-0.1.7/pyasn1/type/univ.py", line 979, in setComponentByPosition
self._verifyComponent(idx, value)
File "/data/aman/cdr/lib/pyasn1-0.1.7/pyasn1/type/univ.py", line 751, in _verifyComponent
raise error.PyAsn1Error('Component type error %r vs %r' % (t, value))
pyasn1.error.PyAsn1Error: Component type error MiepPullWtdr() vs MiepPullWtdr().setComponentByPosition(0, Integer(6555))
有什么帮助吗?谢谢
MiepPullWtdr
类型在其独立定义中与作为 ChoiceData
组件的 ASN.1 标记方式存在不一致。我不确定你的意图到底是什么,这里可能是许多一致版本之一:
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())