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, ""