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)

相关推荐
Csvn1 天前
🌟 LangChain 30 天保姆级教程 · Day 13|OutputParser 进阶!让 AI 输出自动转为结构化对象,并支持自动重试!
python·langchain
cch89181 天前
Python主流框架全解析
开发语言·python
Java成神之路-1 天前
SpringMVC 响应实战指南:页面、文本、JSON 返回全流程(Spring系列13)
java·spring·json
sg_knight1 天前
设计模式实战:状态模式(State)
python·ui·设计模式·状态模式·state
好运的阿财1 天前
process 工具与子agent管理机制详解
网络·人工智能·python·程序人生·ai编程
张張4081 天前
(域格)环境搭建和编译
c语言·开发语言·python·ai
weixin_423533991 天前
【Windows11离线安装anaconda、python、vscode】
开发语言·vscode·python
Ricky111zzz1 天前
leetcode学python记录1
python·算法·leetcode·职场和发展
小白学大数据1 天前
Selenium+Python 爬虫:动态加载头条问答爬取
爬虫·python·selenium
Hui Baby1 天前
springboot读取配置文件
后端·python·flask