Catch exception

main
Bob Mottram 2021-07-20 21:09:39 +01:00
parent 35219af5ea
commit c30b32553d
1 changed files with 7 additions and 1 deletions

View File

@ -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()