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