【发布时间】:2021-03-27 19:42:02
【问题描述】:
import msgpack
path = 'test.msgpack'
with open(path, "wb") as outfile:
outfile.write(msgpack.packb({ (1,2): 'str' }))
现在工作正常
with open(path, 'rb') as infile:
print(msgpack.unpackb(infile.read()))
错误
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "msgpack/_unpacker.pyx", line 195, in msgpack._cmsgpack.unpackb
ValueError: list is not allowed for map key
(是不是很奇怪,只有在拆包时才检测到错误?)
如何编写或解决 msgpacking 以元组为键的 python dict?
【问题讨论】:
标签: python python-3.x msgpack