Python之Requests模块使用详解
api_get_record.py
1 2 3 4 5 6 | import requests response = requests.get(url = "http://127.0.0.1:8000/api/test123" ) response.raise_for_status() data = response.json() print (data) |
api_add_record.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import requests import json d = { "app_name" : "test123" , "system_name" : "test123" , "instance_id" : "test123" , "resource_name" : "test123" , "env_region" : "test123" , "status" : 0 } header = { "content-type" : "application/json" } data = json.dumps(d) response = requests.post(url = "http://127.0.0.1:8000/api/add/" , data = data, headers = header) print (response.text) |
api_update_record.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import requests import json d = { "app_name" : "test126" , "system_name" : "test126" , "instance_id" : "test126" , "resource_name" : "test126" , "env_region" : "test126" , "status" : 0 } header = { "content-type" : "application/json" } data = json.dumps(d) response = requests.put(url = "http://127.0.0.1:8000/api/update/test123/" , data = data, headers = header) print (response.text) |
api_delete_record.py
1 2 3 4 5 6 | import requests response = requests.delete(url = "http://127.0.0.1:8000/api/delete/test126" ) response.raise_for_status() data = response.json() print (data) |
分类:
Django
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
2020-08-25 Redis Sentinel的实现原理与简单搭建