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)

  

posted @   Oops!#  阅读(38)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
历史上的今天:
2020-08-25 Redis Sentinel的实现原理与简单搭建
点击右上角即可分享
微信分享提示