speaker.py 优化
This commit is contained in:
parent
76b1fa0b82
commit
d388871e7c
|
@ -7,6 +7,7 @@ import logging
|
||||||
import requests
|
import requests
|
||||||
from rest_framework.exceptions import APIException, ParseError
|
from rest_framework.exceptions import APIException, ParseError
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from requests.exceptions import RequestException
|
||||||
|
|
||||||
from apps.third.errors import SP_REQUEST_ERROR
|
from apps.third.errors import SP_REQUEST_ERROR
|
||||||
from apps.third.models import Tlog
|
from apps.third.models import Tlog
|
||||||
|
@ -61,6 +62,7 @@ class SpClient:
|
||||||
files = {'file': open(settings.BASE_DIR + file_path_rela, 'rb')}
|
files = {'file': open(settings.BASE_DIR + file_path_rela, 'rb')}
|
||||||
if params:
|
if params:
|
||||||
url = url.format(**params)
|
url = url.format(**params)
|
||||||
|
try:
|
||||||
r = getattr(requests, method)('{}{}'.format(settings.SP_BASE_URL, url),
|
r = getattr(requests, method)('{}{}'.format(settings.SP_BASE_URL, url),
|
||||||
headers=self.headers, params=params, json=json,
|
headers=self.headers, params=params, json=json,
|
||||||
timeout=timeout, files=files, verify=False)
|
timeout=timeout, files=files, verify=False)
|
||||||
|
@ -78,6 +80,7 @@ class SpClient:
|
||||||
return 'fail', err_detail
|
return 'fail', err_detail
|
||||||
# self.handle_log(result='success', response=ret)
|
# self.handle_log(result='success', response=ret)
|
||||||
return 'success', ret
|
return 'success', ret
|
||||||
|
except RequestException:
|
||||||
self.handle_log(result='error', response=ret)
|
self.handle_log(result='error', response=ret)
|
||||||
if raise_exception:
|
if raise_exception:
|
||||||
raise APIException(**SP_REQUEST_ERROR)
|
raise APIException(**SP_REQUEST_ERROR)
|
||||||
|
|
Loading…
Reference in New Issue