Commit 1060280a by jiaqiying

增加通用请求方法,增加斑马信用的配置类

parent 269f589b
#coding:utf-8
import json
import logging
import requests
from config import BaseConfig
def request_main(url, headers, method, data):
"""封装requests的通用请求方法"""
res = None
if headers == None or headers == {}:
# 如果传的headers为空,使用通用headers
headers = BaseConfig.headers
header_content_type = headers["Content-Type"]
try:
if method.upper() == "GET":
res = requests.get(url=url, headers=headers, params=data)
elif method.upper() == "POST":
if header_content_type in ["application/x-www-form-urlencoded"]: #
res = requests.post(url=url, headers=headers, )
elif header_content_type == "application/json":
res = requests.post(url=url, headers=headers, data=json.dumps(data))
except Exception as e:
logging.log(str(e))
raise Exception
if res != None:
return res.json()
return res
\ No newline at end of file
#coding:utf-8
class BaseConfig():
"""基础配置类"""
# 请求头
headers = {'Content-Type': 'application/json; charset=utf-8'}
# 当前运行的产品名
current_product = ""
class BMCConfig(BaseConfig):
"""斑马信用app的配置类"""
pass
class DingTalk(BaseConfig):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment