Closed
Description
With msgpack 1.0.0, this works:
import msgpack
from msgpack.fallback import Packer
import datetime
dt = datetime.datetime(2020, 7, 24, 0, 37, 28, 190432,
tzinfo=datetime.timezone.utc)
packed = Packer(datetime=True).pack(dt)
print(msgpack.
55C7
unpackb(packed, timestamp=3))
packed = msgpack.Packer(datetime=True).pack(dt)
print(msgpack.unpackb(packed, timestamp=3))
But, without tzinfo, the Cython version fails:
import msgpack
from msgpack.fallback import Packer
import datetime
dt = datetime.datetime(2020, 7, 24, 0, 37, 28, 190432)
packed = Packer(datetime=True).pack(dt)
print(msgpack.unpackb(packed, timestamp=3))
packed = msgpack.Packer(datetime=True).pack(dt)
print(msgpack.unpackb(packed, timestamp=3))
2020-07-24 07:37:28.190432+00:00
Traceback (most recent call last):
File "test_msgpack.py", line 10, in <module>
packed = msgpack.Packer(datetime=True).pack(dt)
File "msgpack/_packer.pyx", line 286, in msgpack._cmsgpack.Packer.pack
File "msgpack/_packer.pyx", line 292, in msgpack._cmsgpack.Packer.pack
File "msgpack/_packer.pyx", line 289, in msgpack._cmsgpack.Packer.pack
File "msgpack/_packer.pyx", line 283, in msgpack._cmsgpack.Packer._pack
TypeError: can not serialize 'datetime.datetime' object
Should we make the Python fallback implementation stricter? I can create a PR.
Metadata
Metadata
Assignees
Labels
No labels