我正在尝试使用序列化程序将我的 JSON 数据存储到数据库中。我创建了一个 API 并在邮递员中使用。像 :
POST 端点:API/transaction
和带有JSON
格式的数据
在我加载到序列化程序的地方,它返回一个错误。我也在shell中测试过。我在调试工具中没有得到确切的错误。
我的序列化程序是:
class TransactionSerializer(ma.ModelSchema):
"""transaction validation"""
partner_client_id = fields.String(required=True)
agent_id = fields.String(required=True)
agent_msisdn = fields.String(required=True)
code = fields.Integer(required=True)
title = fields.String(required=False)
price = fields.String(required=True)
currency = fields.String(required=False)
user_msisdn = fields.String(required=True)
requested_ip = fields.String(required=False)
platform = fields.String(required=False)
is_recurring = fields.Boolean(required=False)
class Meta:
"""Meta class."""
model = Transaction
这是蟒蛇壳
>>> from app.serializer.transaction_serializer import TransactionSerializer
>>> transaction_serializer = TransactionSerializer()
>>> trn_json ={
... "partner_client_id": "CLIENTID009",
... "agent_id": "agent222",
... "agent_msisdn": "8801831803255",
... "code": "10",
... "title": "10 Days Unlimited ",
... "price": "10.00",
... "currency": "BDT",
... "user_msisdn": "8801925533362",
... "requested_ip": "127.0.0.1",
... "platform": "universal",
... "is_recurring": True
... }
>>> trn_json
{'partner_client_id': 'CLIENTID009', 'agent_id': 'agent222', 'agent_msisdn': '8801831803255', 'code': '10', 'title': '10 Days Unlimited ', 'price': '10.00', 'currency': 'BDT', 'user_msisdn': '8801925533362', 'requested_ip': '127.0.0.1', 'platform': 'universal', 'is_recurring': True}
>>> transaction, errors = transaction_serializer.load(trn_json)
Traceback (most recent call last):
File "<console>", line 1, in <module>
TypeError: 'Transaction' object is not iterable