[Pyasn1]: raise error.PyAsn1Error('Component type error %r vs %r' % (t, value))
<p>I have only one choice and within that choice I want to pass the object of the class with only one field. </p>

<p>Here is my code snippet:-</p>

<pre><code>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)
</code></pre>

<p>When I run my script test.py, it throws this error:-</p>

<pre><code>Traceback (most recent call last):
  File "test.py", line 18, in &lt;module&gt;
  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))
</code></pre>

<p>Any help? Thanks.</p>

<p>There is an inconsistency in how <code>MiepPullWtdr</code> type is ASN.1 tagged in its stand-alone definition versus as a <code>ChoiceData</code> component. I am not sure what exactly your intention is, here is one of possibly many consistent versions:</p>

<pre><code>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())
</code></pre>

python pyasn1