From 4fb30f4c054a44080c64b95dddbf76890e4c96c9 Mon Sep 17 00:00:00 2001 From: "joel.clement" Date: Fri, 18 Jun 2021 11:00:33 +0200 Subject: [PATCH] fix/thumbnails-proxy --- apptax/taxonomie/filemanager.py | 14 +++++++++++++- config.py.sample | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apptax/taxonomie/filemanager.py b/apptax/taxonomie/filemanager.py index 9570c753..594645f4 100644 --- a/apptax/taxonomie/filemanager.py +++ b/apptax/taxonomie/filemanager.py @@ -78,11 +78,23 @@ def url_to_image(url): """ Récupération d'une image à partir d'une url """ - r = requests.get(url, stream=True) + + r = requests.get( + url, + stream=True, + proxies={ + "http": current_app.config.get('HTTP_PROXY'), + "https": current_app.config.get('HTTPS_PROXY') + } + ) + + if (r.status_code >=400): + raise Exception("Pb with request : status code {}".format(r.status_code)) try: img = Image.open(io.BytesIO(r.content)) except IOError: raise Exception("Media is not an image") + return img diff --git a/config.py.sample b/config.py.sample index e0317395..6ccc6bc2 100644 --- a/config.py.sample +++ b/config.py.sample @@ -27,3 +27,7 @@ PASS_METHOD='hash' # ID APPLICATION TaxHub # User in the authentification submodule to avoid token conflict between app on the same server ID_APP = 2 + +# PROXIES +HTTP_PROXY = None +HTTPS_PROXY = None \ No newline at end of file