From b38b76ef81ecc3ca82b7b1cd8905051a8f83d706 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 11 Apr 2022 14:39:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=89=E6=96=B9=E6=8E=A5=E5=8F=A3=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/third/serializers.py | 2 +- apps/third/tapis.py | 4 ++++ apps/utils/dahua.py | 2 +- apps/utils/xunxi.py | 13 +++++++++---- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/apps/third/serializers.py b/apps/third/serializers.py index 4d27a090..c76827e5 100644 --- a/apps/third/serializers.py +++ b/apps/third/serializers.py @@ -12,4 +12,4 @@ class RequestCommonSerializer(serializers.Serializer): method = serializers.ChoiceField(label='请求方法', choices=method_choice, required=False) params = serializers.JSONField(label='请求参数', required=False, allow_null=True) json = serializers.JSONField(label='请求body(json格式)', required=False, allow_null=True) - code = serializers.CharField(label='请求短标识', required=False) \ No newline at end of file + code = serializers.CharField(label='请求短标识', required=False, allow_null=True) \ No newline at end of file diff --git a/apps/third/tapis.py b/apps/third/tapis.py index c90979e1..3da430df 100644 --- a/apps/third/tapis.py +++ b/apps/third/tapis.py @@ -1,5 +1,9 @@ # 大华API接口 dhapis = { + "dept_tree":{ + "url":"/evo-apigw/evo-brm/1.2.0/department/tree", + "method":"post" + }, "dept_create":{ "url":"/evo-apigw/evo-brm/1.0.0/department/add", "method":"post" diff --git a/apps/utils/dahua.py b/apps/utils/dahua.py index c9ac95a7..95feff48 100644 --- a/apps/utils/dahua.py +++ b/apps/utils/dahua.py @@ -90,7 +90,7 @@ class DhClient: self.request(url, method, params, json, timeout) # 重新请求 else: if ret['code'] not in ['0', '100', '00000', '1000', 0, 100, 1000]: - detail = '{}|{}{}'.format(str(ret['code']), ret.get('errMsg',''), ret.get('desc', '')) + detail = '大华错误:' + '{}|{}{}'.format(str(ret['code']), ret.get('errMsg',''), ret.get('desc', '')) err_detail = dict(detail=detail, code='dh_'+str(ret['code'])) if raise_exception: raise ParseError(**err_detail) diff --git a/apps/utils/xunxi.py b/apps/utils/xunxi.py index 8d185229..1ac98b5b 100644 --- a/apps/utils/xunxi.py +++ b/apps/utils/xunxi.py @@ -58,7 +58,7 @@ class XxClient: self.isRuning = False self.t.join() - def request(self, url:str, method:str='post', params=dict(), json=dict(), timeout=20): + def request(self, url:str, method:str='post', params=dict(), json=dict(), timeout=20, raise_exception=True): params['accessToken'] = self.token json['username'] = self.username json['buildId'] = settings.XX_BUILDID @@ -74,17 +74,22 @@ class XxClient: else: r = getattr(requests, method)('{}{}'.format(settings.XX_BASE_URL, url) , params=params, json=json, verify=False) - # if settings.DEBUG: - # print_roundtrip(r) + if settings.DEBUG: + print_roundtrip(r) ret = r.json() if ret.get('errorCode') == '1060000': self.get_token() # 重新获取token self.request(url, method, params, json, timeout) # 重新请求 else: if ret['errorCode'] != 0: - return 'fail', dict(detail='|'.join(ret['errorMsg']), + err_detail = dict(detail='寻息错误:' + '|'.join(ret['errorMsg']), code='xx_' + str(ret['errorCode'])) + if raise_exception: + raise ParseError(**err_detail) + return 'fail', err_detail return 'success', ret['data'] + if raise_exception: + raise APIException(**XX_REQUEST_ERROR) return 'error', XX_REQUEST_ERROR xxClient = XxClient() \ No newline at end of file