Inserting JSON into MySQL using Python

前端 未结 9 895
我在风中等你
我在风中等你 2020-12-08 03:50

I have a JSON object in Python. I am Using Python DB-API and SimpleJson. I am trying to insert the json into a MySQL table.

At moment am getting errors and I believ

9条回答
  •  隐瞒了意图╮
    2020-12-08 04:14

    You need to get a look at the actual SQL string, try something like this:

    sqlstr = "INSERT INTO tweets_unprocessed (text, created_at, twitter_id, user_id, user_screen_name, json) VALUES (%s,%s,%s,%s,%s,%s)", (status.get('text'), status.get('created_at'), status.get('id'), status.get('user', {}).get('id'), status.get('user', {}).get('screen_name'), status)
    print "about to execute(%s)" % sqlstr
    twitdb.execute(sqlstr)
    

    I imagine you are going to find some stray quotes, brackets or parenthesis in there.

提交回复
热议问题