我是 asn1 的新手,我的议程是将 python 字典转换为 .asn 格式。当我运行以下代码时,出现以下错误
ParseError:第 1 行第 1 列的 ASN.1 语法无效:'>!<"':预期的模块引用。
from __future__ import print_function
from binascii import hexlify
import asn1tools
specification=""""
Foo DEFINITIONS ::= BEGIN
Question ::= SEQUENCE {
id INTEGER,
question IA5String
}
Answer ::= SEQUENCE {
id INTEGER,
answer BOOLEAN
}
END
""""
Foo = asn1tools.compile_string(specification, 'uper')
Question = {'id': 2, 'question': u'Hi how r u?!'}
Answer ={'id': 2, 'answer': u'Hi i am good'}
encoded = Foo.encode('Question', Question)
encoded1 = Foo.encode('Answer', Answer)
decoded = Foo.decode('Question', Question)
print('Question:', Question)
print('Encoded:', hexlify(encoded).decode('ascii'))
print('Decoded:', decoded)