标签:mes eth har max edit alt ade raise char
api/baseview.py
把application/json做json.loads改成dict类型
class BaseView(View): def dispatch(self, request, *args, **kwargs): if request.method == "POST": if "application/json" in self.request.META["CONTENT_TYPE"]: if request.body: request.json_data = json.loads(request.body) else: request.json_data = {} return super(BaseView, self).dispatch(request, *args, **kwargs)
api/response.py
class FailJsonResponse(JsonResponse): def __init__(self, message, **kwargs): data = {} if kwargs: data.update(kwargs) # high priority data.update({ "result": False, "message": message }) if "data" not in data: data["data"] = {} super(FailJsonResponse, self).__init__(data)
api/utils.py
def agent_header(sid, token): return { "Content-Type": "application/json", "X-ID": str(sid), "X-TOKEN": str(token) } def check_agent_health(bk_server): resp = http.http_request( method="GET", url="http://%s:%s/v1/app/healthz" % (bk_server.ip_address, bk_server.ip_port), headers=agent_header(bk_server.s_id, bk_server.token) ) if resp.get("error") != 0: raise Exception("%s agent return not zero" % bk_server.ip_address) return resp
api/models.py
class BkServer(models.Model): name = models.CharField(u‘名称‘, max_length=20) s_id = models.UUIDField(u‘服务ID‘, default=uuid.uuid4, editable=False) token = models.UUIDField(default=uuid.uuid4, editable=False)
标签:mes eth har max edit alt ade raise char
原文地址:https://www.cnblogs.com/jabbok/p/12230227.html