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__':