Python之Requests模块使用详解

 

api_get_record.py

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

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

 

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

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 @ 2023-08-25 09:08  Oops!#  阅读(31)  评论(0编辑  收藏  举报