From 58dfe8f04b0e507ea97af7ba942f86c1a11218ec Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 15 Sep 2022 10:06:44 +0200 Subject: [PATCH] sco_photos: exception handling --- app/scodoc/sco_photos.py | 12 +++++------- sco_version.py | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/scodoc/sco_photos.py b/app/scodoc/sco_photos.py index 6145c718c..b16335ae2 100644 --- a/app/scodoc/sco_photos.py +++ b/app/scodoc/sco_photos.py @@ -49,6 +49,7 @@ import os import random import requests import time +import traceback import PIL from PIL import Image as PILImage @@ -372,22 +373,19 @@ def copy_portal_photo_to_fs(etud: dict): portal_timeout = sco_preferences.get_preference("portal_timeout") error_message = None try: - log(f"copy_portal_photo_to_fs: getting {url}") r = requests.get(url, timeout=portal_timeout) except requests.ConnectionError: - log("copy_portal_photo_to_fs: ConnectionError.") error_message = "ConnectionError" except requests.Timeout: - log("copy_portal_photo_to_fs: Timeout.") error_message = "Timeout" except requests.TooManyRedirects: - log("copy_portal_photo_to_fs: TooManyRedirects.") error_message = "TooManyRedirects" except requests.RequestException: - # log("download failed: exception:\n%s" % traceback.format_exc()) - # log("called from:\n" + "".join(traceback.format_stack())) - log("copy_portal_photo_to_fs: unknown requests error.") + error_message = "unknown requests error" if error_message is not None: + log("sco_photos: download failed") + log(traceback.format_exc()) + log(f"copy_portal_photo_to_fs: {error_message}") return ( None, f"""{etud["nomprenom"]}: erreur chargement de {url}\n{error_message}""", diff --git a/sco_version.py b/sco_version.py index 2faa78ebd..1ea3e57a9 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.3.38" +SCOVERSION = "9.3.39" SCONAME = "ScoDoc"