1
0
forked from ScoDoc/ScoDoc

sco_photos: exception handling

This commit is contained in:
Emmanuel Viennet 2022-09-15 10:06:44 +02:00
parent 0657bf0cb2
commit 58dfe8f04b
2 changed files with 6 additions and 8 deletions

View File

@ -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}""",

View File

@ -1,7 +1,7 @@
# -*- mode: python -*-
# -*- coding: utf-8 -*-
SCOVERSION = "9.3.38"
SCOVERSION = "9.3.39"
SCONAME = "ScoDoc"