增加音响接口
This commit is contained in:
parent
0ab3ae31af
commit
c7318fe8ee
|
@ -42,7 +42,8 @@ class SpTestView(APIView):
|
||||||
|
|
||||||
音响测试接口
|
音响测试接口
|
||||||
"""
|
"""
|
||||||
_, res = spClient.request(**spapis['device_list'])
|
params = {"page": 1, "pageSize": 10000}
|
||||||
|
_, res = spClient.request(**spapis['device_list'], params=params)
|
||||||
return Response(res)
|
return Response(res)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,11 +36,11 @@ class SpClient:
|
||||||
"password": self.password
|
"password": self.password
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
r = requests.post(params=params,
|
r = requests.post(json=params,
|
||||||
url=settings.SP_BASE_URL + '/api/users/login', verify=False)
|
url=settings.SP_BASE_URL + '/api/users/login', verify=False)
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
ret = r.json()
|
ret = r.json()
|
||||||
self.headers['Authorization'] = 'bearer ' + ret['user']['token']
|
self.headers['Authorization'] = 'Bearer ' + ret['user']['token']
|
||||||
time.sleep(3600)
|
time.sleep(3600)
|
||||||
|
|
||||||
def get_token(self):
|
def get_token(self):
|
||||||
|
@ -53,8 +53,7 @@ class SpClient:
|
||||||
r = requests.post(params=params, url=settings.SP_BASE_URL + '/evo-apigw/evo-oauth/oauth/token', verify=False)
|
r = requests.post(params=params, url=settings.SP_BASE_URL + '/evo-apigw/evo-oauth/oauth/token', verify=False)
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
ret = r.json()
|
ret = r.json()
|
||||||
print(ret)
|
self.headers['Authorization'] = 'Bearer ' + ret['user']['token']
|
||||||
self.headers['Authorization'] = 'bearer ' + ret['user']['token']
|
|
||||||
self.isGetingToken = False
|
self.isGetingToken = False
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
|
@ -93,17 +92,24 @@ class SpClient:
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise APIException(**SP_REQUEST_ERROR)
|
raise APIException(**SP_REQUEST_ERROR)
|
||||||
return 'error', SP_REQUEST_ERROR
|
return 'error', SP_REQUEST_ERROR
|
||||||
# if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
# print_roundtrip(r)
|
print_roundtrip(r)
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
ret = r.json()
|
ret = r.json()
|
||||||
if 'code' in ret and ret['code'] not in ['0', '100', '00000', '1000', 0, 100, 1000]:
|
if 'code' in ret and ret['code'] not in ['0', '100', '00000', '1000', 0, 100, 1000]:
|
||||||
detail = '音响错误:{}'.format(str(ret['msg']))
|
detail = '音响错误:{}'.format(str(ret.get('msg', '')))
|
||||||
err_detail = dict(detail=detail, code='sp_'+str(ret['code']))
|
err_detail = dict(detail=detail, code='sp_'+str(ret['code']))
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise ParseError(**err_detail)
|
raise ParseError(**err_detail)
|
||||||
return 'fail', dict(detail=detail, code='sp_'+str(ret['code']))
|
return 'fail', dict(detail=detail, code='sp_'+str(ret['code']))
|
||||||
return 'success', ret
|
return 'success', ret
|
||||||
|
else:
|
||||||
|
ret = r.json()
|
||||||
|
detail = '音响错误:{}-{}'.format(str(ret.get('type', '')), str(ret.get('message', '')))
|
||||||
|
err_detail = dict(detail=detail, code='sp_'+str(ret['code']))
|
||||||
|
if raise_exception:
|
||||||
|
raise ParseError(**err_detail)
|
||||||
|
return 'fail', dict(detail=detail, code='sp_'+str(ret['code']))
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise APIException(**SP_REQUEST_ERROR)
|
raise APIException(**SP_REQUEST_ERROR)
|
||||||
return 'error', SP_REQUEST_ERROR
|
return 'error', SP_REQUEST_ERROR
|
||||||
|
|
Loading…
Reference in New Issue