From 94e183c661ba867caa1a838473c22525123c35e5 Mon Sep 17 00:00:00 2001 From: liuyebo <1515783401@qq.com> Date: Wed, 10 Jul 2024 09:34:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=B8=B4=E6=97=B6=E5=9B=BE?= =?UTF-8?q?=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- photo_mask.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/photo_mask.py b/photo_mask.py index 5e2715f..52fdb39 100644 --- a/photo_mask.py +++ b/photo_mask.py @@ -255,10 +255,18 @@ def photo_mask(pk_phhd, content): with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file: cv2.imwrite(temp_file.name, image) cv2.imwrite(f"./mask_test2/{phrec.cfjaddress}.jpg", image) - for i in range(3): - is_upload_success = ucloud.upload_file(phrec.cfjaddress, temp_file.name) - if is_upload_success: - break + try: + for i in range(3): + is_upload_success = ucloud.upload_file(phrec.cfjaddress, temp_file.name) + if is_upload_success: + break + except Exception as e: + logging.error("上传图片出错", exc_info=e) + finally: + try: + os.remove(temp_file.name) + except Exception as e: + logging.info(f"删除临时文件 {temp_file.name} 时出错", exc_info=e) if __name__ == '__main__':