2016-09-06 11 views
0

하나의 선택 항목 만 있고 그 선택 내에서 하나만 사용하여 클래스 개체를 전달하려고합니다. 들.: 오류 발생 .PyAsn1Error ('구성 요소 유형 오류 % r 대 % r'% (t, 값))

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)) 

어떤 도움 - : 내 스크립트 test.py를 실행하면

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) 

, 그것은이 오류가 발생합니다 - : 여기

내 코드인가? 감사.

답변

0

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())