flask学习笔记-01-传送dict信息

1-1 server端:

复制代码
requests.post,requests.data
python 复制代码
import json

from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route("/test", methods=["POST"])
def test():

    out = request.data
    print(out, type(out))
    out = json.loads(out)
    print(out, type(out))

    return jsonify({"1": "2"})


if __name__ == "__main__":
    app.run(host="0.0.0.0", port="9000", debug=False, threaded=True)  # debug=True causes Restarting with stat

1-2 client 端:

python 复制代码
import json
import requests

DETECTION_URL = "http://127.0.0.1:9000/test"

d1 = {"a": "b"}

response = requests.post(DETECTION_URL, data=json.dumps(d1))
print(response.json())

2-1 server端:

requests.post,requests.json

python 复制代码
import json

app = Flask(__name__)

@app.route("/test", methods=["POST"])
def test():

    config = dict(request.json)
    print(config, type(config))
    b = request.json.get("a")

    return jsonify({"1": "2"})


if __name__ == "__main__":
    app.run(host="0.0.0.0", port="9000", debug=False, threaded=True)  # debug=True causes Restarting with stat

2-2 client 端:

python 复制代码
import json
import requests

DETECTION_URL = "http://127.0.0.1:9000/test"

d1 = {"a": "b"}

response = requests.post(DETECTION_URL, json=d1)
print(response.json())
  1. 哇, linux nohup命令真是一个优秀的命令,将终端上打出的信息都输到nohup.out里了。

    nohup python3 -u example_flask_server.py &

Linux nohup 命令 | 菜鸟教程 (runoob.com)

相关推荐
郭庆汝1 小时前
pytorch、torchvision与python版本对应关系
人工智能·pytorch·python
测试杂货铺4 小时前
Jmeter(六):json断言元件,jmeter参数化实现
jmeter·json
思则变4 小时前
[Pytest] [Part 2]增加 log功能
开发语言·python·pytest
漫谈网络5 小时前
WebSocket 在前后端的完整使用流程
javascript·python·websocket
try2find6 小时前
安装llama-cpp-python踩坑记
开发语言·python·llama
博观而约取7 小时前
Django ORM 1. 创建模型(Model)
数据库·python·django
精灵vector8 小时前
构建专家级SQL Agent交互
python·aigc·ai编程
专注VB编程开发20年9 小时前
C#,VB.NET从JSON数据里提取数组中的对象节点值
c#·json·.net
Zonda要好好学习9 小时前
Python入门Day2
开发语言·python
Vertira9 小时前
pdf 合并 python实现(已解决)
前端·python·pdf