ソースを参照

add exception message

ming 3 年 前
コミット
162d292eb2
1 ファイル変更16 行追加0 行削除
  1. 16 0
      main.py

+ 16 - 0
main.py

@@ -111,6 +111,22 @@ async def progress_page():
 
 @app.post("/make_anchor_video_v2")
 async def make_anchor_video_v2(req:request):
+    for txt in req.text_content:
+        if re.search('[a-zA-Z]', txt) !=None:
+            return {'msg':'輸入字串不能包含英文字!'}
+    
+    for imgu in image_urls:
+        try:
+            if get_url_type(imgu) =='video/mp4':
+                r=requests.get(imgu)
+                f=open(dir_photo+name_hash+"/"+str(img_num)+".mp4",'wb')
+            else:
+                im = Image.open(requests.get(imgu, stream=True).raw)
+                im= im.convert("RGB")
+        except:
+            return {'msg':"無法辨別圖片網址"+imgu}
+    
+
     db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
     log_table = db['history_input']
     txt_content_seperate_by_dot = ''