Python:如何将有效的uuid从String转换为UUID4?

时间:2019-05-28 05:40:28

标签: python-3.x

邮递员正在向以python编写的函数发送请求。参数中有id。而且这种类型的id是uniqueidetifier(uuid4),但作为邮递员和json都是字符串。

类型uuid4出现“ AttributeError:'str'对象没有属性'id'”错误

python请求:


{
    "items": [
        {
            "id": "18f72017-4a8b-4c82-bf0d-97b3fa01061b",
            "total": 1000,
            "comment": "test 1"
        },
        {
            "id": "e54cf3a8-3fec-4321-bb43-8bcd106bf29d",
            "total": 500,
            "comment": "test 2"
        }
    ]

}

def setpaymentapprove(work: directives.work, **items):
    for item in items:
        product = work.session.query(Product).filter(Product.id == item.id).first()

        if product is not None:
            product.total = item.total
            product.comment = item.comment

        work.session.add(product)
        work.session.commit()
        return BaseDto(True).toJson()

“ AttributeError:'str'对象没有属性'id'”

谢谢。

0 个答案:

没有答案