Python type error

Asked 2 years ago, Updated 2 years ago, 54 views

Hello, I am making a web server with Flask


@app.route('/licanse/minus/<licanse_c>')
def minus(licanse_c):
    licanse_find = list(db.user.find({"licanse": licanse_c}, {'_id': False}))
    if licanse_find == []:
        return {"minus": "Licanse does not exist"}
    else:
        print(licanse_find)
        conversion = json.dumps(licanse_find)
        licanse_json = json.loads(conversion)
        org_sms_stock = licanse_json["sms"]
        sms_stock = licanse_json["sms"]
        sms_stock = int(sms_stock)
        sms_stock = sms_stock-1
        org = { "sms": f"{org_sms_stock}" }
        new = { "$set": { "sms": f"{sms_stock}" } }
        db.update_one(org, new)
        return {"minus": "", "result": f"{org_sms_stock} => {sms_stock}"}

Error in org_sms_stock = license_json["sms"] The content is TypeError: list indexes must be integrers or slacks, not str How do I solve this?

This is what json is this

[{'sms': '50', 'licanse': 'e144e7ca-6e31-4f1c-82ee-8dd473718f00'}]

python flask database json

2022-09-20 11:39

1 Answers

The dict object is in the list object.

org_sms_stock = licanse_json[0]["sms"]


2022-09-20 11:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.