marshallow-dataclass引发验证异常

时间:2019-09-29 16:22:39

标签: python marshmallow python-dataclasses python-3.7.4

我有一个简单的例子:

from dataclasses import dataclass
import marshmallow_dataclass

@dataclass
class Tst:
    fld: str


if __name__ == "__main__":
    objct = marshmallow_dataclass.class_schema(Tst)().load("{\"fld\":\"value\"}")

我希望这能从JSON反序列化对象,但是结果是以下回溯:

Original exception was:
Traceback (most recent call last):
  File "./main.py", line 13, in <module>
    objct = marshmallow_dataclass.class_schema(Tst)().load("\"fld\":\"value\"")
  File "/home/krjoff/.local/lib/python3.7/site-packages/marshmallow/schema.py", line 720, in load
    data, many=many, partial=partial, unknown=unknown, postprocess=True
  File "/home/krjoff/.local/lib/python3.7/site-packages/marshmallow/schema.py", line 898, in _do_load
    raise exc
marshmallow.exceptions.ValidationError: {'_schema': ['Invalid input type.']}

有人可以建议如何解决此问题吗?

0 个答案:

没有答案