【发布时间】:2019-10-16 12:24:23
【问题描述】:
我有 JSON 文件 data.json 我想通过 curl 发送到一个瓶子服务器,然后从文件中获取值。问题是它没有在数据库中存储任何内容。如何存储通过 JSON 文件传递的值?
卷曲命令
curl -X POST -i -d @data.json --header "Content-Type: application/json" http://192.168.1.12:8080/
bottle.py
@route('/', method='POST')
def index():
n1 = request.POST.get("maclist", "").strip()
n2 = request.POST.get("signallist", "").strip()
conn = sqlite3.connect('db/users.db')
c = conn.cursor()
c.execute("INSERT INTO users (MAC,SIGNAL) VALUES(?,?)", (n1,n2))
conn.commit()
return "Items added."
数据.json
{
"maclist": [
"a1:b2:c3:d4:e5:f6"
],
"signallist": [
"-25"
]
}
【问题讨论】:
-
你能在服务器端正确读取maclist和signallist吗?用瓶子?
-
@gachdavit 这正是我想做的。我通过 curl 发送 post 请求,我收到 200。
-
我添加了答案,检查一下。
标签: python sqlite curl post bottle