python flask API 返回状态码

@app.route('/dailyupdate', methods = ['POST','GET'])
def dailyUpdate():
try:
db=MySQLdb.connect("localhost","root","abc123_","videomgr")
cursor=db.cursor()
if request.method == 'POST':
accountNum = request.form['accountNum']
machineName = request.form['machineName']
updateTime = request.form['updateTime']
sql="INSERT INTO `publishinfo` (`account_count`, `client_name`, `update_time`) VALUES (%d, '%s', '%s')" %(int(accountNum), machineName, updateTime)
cursor.execute(sql)
db.commit()
return 'update success', 200
except Exception as e:
db.rollback()

 

client:

r=requests.post(url,data=data, headers=headers)

print(r.status_code)

 

status_code 会是 API 中返回的数字:200

posted @ 2020-04-28 11:07  modentime  阅读(4248)  评论(0编辑  收藏  举报