From: Alessandro Astone Date: Sat, 14 May 2022 17:50:44 +0000 (+0200) Subject: http: Handle malformed urls X-Git-Tag: 1.3.0~35 X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/waydroid.git/commitdiff_plain/d0f96e44cc60f7fee2d338e28a44961984f45c89?ds=inline http: Handle malformed urls --- diff --git a/tools/helpers/http.py b/tools/helpers/http.py index 68031c3..ff81957 100644 --- a/tools/helpers/http.py +++ b/tools/helpers/http.py @@ -138,10 +138,13 @@ def retrieve(url, headers=None): if headers is None: headers = {} - req = urllib.request.Request(url, headers=headers) try: + req = urllib.request.Request(url, headers=headers) with urllib.request.urlopen(req) as response: return 200, response.read() + # Handle malformed URL + except ValueError as e: + return -1, "" # Handle 404 except urllib.error.HTTPError as e: return e.code, ""