From f01015c73b7a969e8d1be493e6e8388c1386515b Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Tue, 6 Aug 2019 21:51:58 +0200 Subject: [PATCH] Tweak OG error handling --- utils/opengraph.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/utils/opengraph.py b/utils/opengraph.py index 91acccd..961243f 100644 --- a/utils/opengraph.py +++ b/utils/opengraph.py @@ -57,10 +57,12 @@ def fetch_og_metadata(user_agent, links): h = requests.head(l, headers={"User-Agent": user_agent}, timeout=3) h.raise_for_status() except requests.HTTPError as http_err: - logger.debug(f"failed to HEAD {l}, got a {http_err.response.status_code}") + logger.debug( + f"failed to HEAD {l}, got a {http_err.response.status_code}: {http_err.response.text}" + ) continue - except requests.Timeout: - logger.debug(f"HEAD {l} timed out") + except requests.RequestException as err: + logger.debug(f"failed to HEAD {l}: {err!r}") continue if not h.headers.get("content-type").startswith("text/html"): @@ -71,10 +73,12 @@ def fetch_og_metadata(user_agent, links): r = requests.get(l, headers={"User-Agent": user_agent}, timeout=5) r.raise_for_status() except requests.HTTPError as http_err: - logger.debug(f"failed to GET {l}, got a {http_err.response.status_code}") + logger.debug( + f"failed to GET {l}, got a {http_err.response.status_code}: {http_err.response.text}" + ) continue - except requests.Timeout: - logger.debug(f"GET {l} timed out") + except requests.RequestException as err: + logger.debug(f"failed to GET {l}: {err!r}") continue r.encoding = "UTF-8"