美文网首页
postman与python进行js数据传输并保存到数据库

postman与python进行js数据传输并保存到数据库

作者: If_54ea | 来源:发表于2019-12-18 20:23 被阅读0次

python端程序(向服务器写入接收到的数据):

from flask import json, request

@main.route('/gxys_sports', methods=['POST', 'GET'])
def predictapp5gxys_sports():
    try:
        global flag1, q, ecg2, rip2, i, flag5
        datas = request.get_data()
        print(datas)    # 查看是否接收到数据
        new_dict = json.loads(datas, encoding='utf-8')
        sj = new_dict['time']
        kk = new_dict['userAccount']
        kk = kk + '_sports'
        kk1 = base[kk]
        sj=int(sj)
        timeArray = time.localtime(sj)
        tt = time.strftime("%Y/%m/%d %H:%M:%S", timeArray)
        charu = {'time': sj, 'date': tt, 'originData': new_dict['originData']}
        kk1.insert(charu)
        print('******')
        print('ok')
        return "{\"status\":\"success\"}"
    except Exception as e:
        app.logger.exception('%s', e)
        return "msg:code{\"status\":\"false\"}"

在poatman中模拟数据的发送(根据python脚本url为http://127.0.0.1:8081/gxys_sports,使用post方式)

test内容 Body内容,传递参数 结果运行结果: 获取正确返回值 python脚本得到正确输出 本地数据库更新

程序正确运行,接口搭建成功

相关文章

网友评论

      本文标题:postman与python进行js数据传输并保存到数据库

      本文链接:https://www.haomeiwen.com/subject/hozunctx.html