json - Python 存入mysql报错,看不出来是什么问题求解答

查看:140
本文介绍了json - Python 存入mysql报错,看不出来是什么问题求解答的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

json转字典 存入mysql 报错 Python3.5 django1.82以上
字典:
dialogue={

"state": "ok",
"errmsg": "",
"data": {
    "total": 26,
    "items": [
        {
            "id": "83013",
            "session_id": "664565",
            "chat_id": "5464",
            "site_id": "5464",
            "visitor_id": "645645",
            "worker_id": "65466",
            "interface": "554",
            "entry_type": "44",
            "finished_type": "45",
            "total_messages": "17",
            "visitor_messages": "9",
            "robot_messages": "2",
            "miss_messages": "9",
            "worker_messages": "6",
            "wait_times": "0",
            "total_times": "531",
            "server_date": "2017-05-01",
            "first_time": "2017-05-01 22:17:57",
            "last_time": "2017-05-01 22:26:48",
            "first_resp": "22632",
            "avg_resp": "28985",
            "robot_tags": "",
            "manual_tags": ""
        },
        {
             "id": "83013",
            "session_id": "664565",
            "chat_id": "5464",
            "site_id": "5464",
            "visitor_id": "645645",
            "worker_id": "65466",
            "interface": "554",
            "entry_type": "44",
            "finished_type": "45",
            "total_messages": "17",
            "visitor_messages": "9",
            "robot_messages": "2",
            "miss_messages": "9",
            "worker_messages": "6",
            "wait_times": "0",
            "total_times": "531",
            "server_date": "2017-05-01",
            "first_time": "2017-05-01 22:17:57",
            "last_time": "2017-05-01 22:26:48",
            "first_resp": "22632",
            "avg_resp": "28985",
            "robot_tags": null,
            "manual_tags": null
        }]}}
        -------------------------------------------
       代码:
        for records in dialogue['data']['items']:
    dialogue_records = Dialogue.objects.all()
    dialogue_validation = dialogue_records.filter(session_id=records['session_id'], chat_id=records['chat_id'])
    if not dialogue_validation:
        print("数据不存在,添加添加数据中ing....")
        Dialogue.objects.create(session_id=records['session_id'], chat_id=records['chat_id'],
                                site_id=records['site_id'],
                                visitor_id=records['visitor_id'], worker_id=records['worker_id'],
                                interface=records['interface'],
                                entry_type=records['entry_type'], finished_type=records['finished_type'],
                                total_messages=records['total_messages'],
                                visitor_messages=records['visitor_messages'],
                                robot_messages=records['robot_messages'], miss_messages=records['miss_messages'],
                                worker_messages=records['worker_messages'], wait_times=records['wait_times'],
                                total_times=records['total_times'],
                                server_date=records['server_date'], first_time=records['first_time'],
                                last_time=records['last_time'], first_resp=['first_resp'],
                                avg_resp=records['avg_resp'], robot_tags=records['robot_tags'],
                                manual_tags=records['manual_tags'])
                                ------------------===========
                                
                            
                             

报错

解决方案

model 问题我model 咩设计好 出现的

这篇关于json - Python 存入mysql报错,看不出来是什么问题求解答的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆