python requests 使用公共函数:get, post, put
import requests
headers = {'Private-Token': "xxx"}
url = "xxx"
def get_request(url,headers):
res = requests.get(url=url,headers=headers)
try:
results = res.json()
except json.JSONDecodeError:
results = res.text
print(f"{results} cannot be converted to Json")
return results
def post_request(url,headers,data):
res = requests.post(url=url,headers=headers,data=data)
try:
results = res.json()
except json.JSONDecodeError:
results = res.text
print(f"{results} cannot be converted to Json")
return results
def put_request(url,headers,data):
res = requests.put(url=url,headers=headers,data=data)
try:
results = res.json()
except json.JSONDecodeError:
results = res.text
print(f"{results} cannot be converted to Json")
return results