From c30b32553d9833faa4dcf22b563da5302e6a7dbe Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 20 Jul 2021 21:09:39 +0100 Subject: [PATCH] Catch exception --- languages.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/languages.py b/languages.py index a1fe7b4d3..9690e4998 100644 --- a/languages.py +++ b/languages.py @@ -214,6 +214,8 @@ def _libretranslate(url: str, text: str, else: url += "translate" + originalText = text + # get any links from the text links = getLinksFromContent(text) @@ -236,7 +238,11 @@ def _libretranslate(url: str, text: str, urlParams = parse.urlencode(ltParams) req = request.Request(url, data=urlParams.encode()) - response = request.urlopen(req) + try: + response = request.urlopen(req) + except BaseException: + print('Unaable to translate: ' + text) + return originalText response_str = response.read().decode()