Improve error handling & abort disconnected requests (#449)

This commit is contained in:
Lianmin Zheng
2024-05-17 05:49:31 -07:00
committed by GitHub
parent 5be9eb8a8c
commit 8210ec60f4
9 changed files with 198 additions and 126 deletions

View File

@@ -93,8 +93,12 @@ def http_request(
data = None
else:
data = bytes(dumps(json), encoding="utf-8")
resp = urllib.request.urlopen(req, data=data, cafile=verify)
return HttpResponse(resp)
try:
resp = urllib.request.urlopen(req, data=data, cafile=verify)
return HttpResponse(resp)
except urllib.error.HTTPError as e:
return HttpResponse(e)
def encode_image_base64(image_path):