|
@@ -15,6 +15,7 @@ import time
|
|
|
import apns2
|
|
|
import boto3
|
|
|
import jpush
|
|
|
+from PIL import UnidentifiedImageError
|
|
|
from boto3.session import Session
|
|
|
from django.views.generic.base import View
|
|
|
from pyfcm import FCMNotification
|
|
@@ -75,7 +76,8 @@ class AiView(View):
|
|
|
logger.info('*****进入into----ai--api,etk={etk}'.format(etk=etk))
|
|
|
if not etk:
|
|
|
return response.json(444)
|
|
|
-
|
|
|
+ dir_path = ''
|
|
|
+ uid = ''
|
|
|
try:
|
|
|
# 解密uid及判断长度
|
|
|
eto = ETkObject(etk)
|
|
@@ -261,6 +263,16 @@ class AiView(View):
|
|
|
AiView.save_cloud_ai_tag(uid, int(n_time), eventType, 0)
|
|
|
return response.json(0)
|
|
|
|
|
|
+ except UnidentifiedImageError as e:
|
|
|
+ if dir_path:
|
|
|
+ self.del_path(dir_path)
|
|
|
+ self.del_path(dir_path + '.jpg')
|
|
|
+ data = {
|
|
|
+ 'errLine': e.__traceback__.tb_lineno,
|
|
|
+ 'errMsg': repr(e)
|
|
|
+ }
|
|
|
+ logger.info(f'rekognition识别异常删除图片 uid:{uid},errMsg={data}')
|
|
|
+ return response.json(48, data)
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
|
data = {
|
|
@@ -271,19 +283,22 @@ class AiView(View):
|
|
|
return response.json(48, data)
|
|
|
|
|
|
def del_path(self, path):
|
|
|
- if not os.path.exists(path):
|
|
|
- return
|
|
|
- if os.path.isfile(path):
|
|
|
- os.remove(path)
|
|
|
- else:
|
|
|
- items = os.listdir(path)
|
|
|
- for f in items:
|
|
|
- c_path = os.path.join(path, f)
|
|
|
- if os.path.isdir(c_path):
|
|
|
- self.del_path(c_path)
|
|
|
- else:
|
|
|
- os.remove(c_path)
|
|
|
- os.rmdir(path)
|
|
|
+ try:
|
|
|
+ if not os.path.exists(path):
|
|
|
+ return
|
|
|
+ if os.path.isfile(path):
|
|
|
+ os.remove(path)
|
|
|
+ else:
|
|
|
+ items = os.listdir(path)
|
|
|
+ for f in items:
|
|
|
+ c_path = os.path.join(path, f)
|
|
|
+ if os.path.isdir(c_path):
|
|
|
+ self.del_path(c_path)
|
|
|
+ else:
|
|
|
+ os.remove(c_path)
|
|
|
+ os.rmdir(path)
|
|
|
+ except Exception as e:
|
|
|
+ print(repr(e))
|
|
|
|
|
|
## 检查是否有符合条件的标签,并且返回标签坐标位置信息
|
|
|
def labelsCoords(self, user_detect_group, rekognition_res, image_size):
|