mirror of https://gitlab.com/bashrc2/epicyon
More exception handling for json decoding
parent
d337f663d9
commit
fbc597256f
11
daemon.py
11
daemon.py
|
@ -21462,7 +21462,16 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
except OSError:
|
except OSError:
|
||||||
print('EX: unable to read file ' + filename)
|
print('EX: unable to read file ' + filename)
|
||||||
if content:
|
if content:
|
||||||
content_json = json.loads(content)
|
try:
|
||||||
|
content_json = json.loads(content)
|
||||||
|
except json.decoder.JSONDecodeError as ex:
|
||||||
|
self._400()
|
||||||
|
print('EX: json decode error ' + str(ex) +
|
||||||
|
' from GET content_json ' +
|
||||||
|
str(content))
|
||||||
|
self.server.getreq_busy = False
|
||||||
|
return
|
||||||
|
|
||||||
msg_str = json.dumps(content_json, ensure_ascii=False)
|
msg_str = json.dumps(content_json, ensure_ascii=False)
|
||||||
msg_str = self._convert_domains(calling_domain,
|
msg_str = self._convert_domains(calling_domain,
|
||||||
referer_domain,
|
referer_domain,
|
||||||
|
|
18
inbox.py
18
inbox.py
|
@ -4608,11 +4608,25 @@ def _inbox_after_initial(server, inbox_start_time,
|
||||||
if onion_domain:
|
if onion_domain:
|
||||||
if onion_domain in message_str:
|
if onion_domain in message_str:
|
||||||
message_str = message_str.replace(onion_domain, domain)
|
message_str = message_str.replace(onion_domain, domain)
|
||||||
message_json = json.loads(message_str)
|
try:
|
||||||
|
message_json = json.loads(message_str)
|
||||||
|
except json.decoder.JSONDecodeError as ex:
|
||||||
|
print('EX: json decode error ' + str(ex) +
|
||||||
|
' from _inbox_after_initial onion ' +
|
||||||
|
str(message_str))
|
||||||
|
inbox_start_time = time.time()
|
||||||
|
return False
|
||||||
if i2p_domain:
|
if i2p_domain:
|
||||||
if i2p_domain in message_str:
|
if i2p_domain in message_str:
|
||||||
message_str = message_str.replace(i2p_domain, domain)
|
message_str = message_str.replace(i2p_domain, domain)
|
||||||
message_json = json.loads(message_str)
|
try:
|
||||||
|
message_json = json.loads(message_str)
|
||||||
|
except json.decoder.JSONDecodeError as ex:
|
||||||
|
print('EX: json decode error ' + str(ex) +
|
||||||
|
' from _inbox_after_initial i2p ' +
|
||||||
|
str(message_str))
|
||||||
|
inbox_start_time = time.time()
|
||||||
|
return False
|
||||||
|
|
||||||
actor = key_id
|
actor = key_id
|
||||||
if '#' in actor:
|
if '#' in actor:
|
||||||
|
|
18
languages.py
18
languages.py
|
@ -168,7 +168,13 @@ def libretranslate_languages(url: str, api_key: str = None) -> []:
|
||||||
with request.urlopen(req) as response:
|
with request.urlopen(req) as response:
|
||||||
response_str = response.read().decode()
|
response_str = response.read().decode()
|
||||||
|
|
||||||
result = json.loads(response_str)
|
try:
|
||||||
|
result = json.loads(response_str)
|
||||||
|
except json.decoder.JSONDecodeError as ex:
|
||||||
|
print('EX: json decode error ' + str(ex) +
|
||||||
|
' from libretranslate_languages ' +
|
||||||
|
str(response_str))
|
||||||
|
return []
|
||||||
if not result:
|
if not result:
|
||||||
return []
|
return []
|
||||||
if not isinstance(result, list):
|
if not isinstance(result, list):
|
||||||
|
@ -283,8 +289,14 @@ def libretranslate(url: str, text: str,
|
||||||
if not response_str:
|
if not response_str:
|
||||||
return original_text
|
return original_text
|
||||||
|
|
||||||
translated_text = \
|
try:
|
||||||
'<p>' + json.loads(response_str)['translatedText'] + '</p>'
|
translated_text = \
|
||||||
|
'<p>' + json.loads(response_str)['translatedText'] + '</p>'
|
||||||
|
except json.decoder.JSONDecodeError as ex:
|
||||||
|
print('EX: json decode error ' + str(ex) +
|
||||||
|
' from libretranslate ' +
|
||||||
|
str(response_str))
|
||||||
|
return original_text
|
||||||
|
|
||||||
# append links form the original text
|
# append links form the original text
|
||||||
if links:
|
if links:
|
||||||
|
|
Loading…
Reference in New Issue