编辑代码

import urllib.request
import urllib.error

try:
    response = urllib.request.urlopen("http://www.jsrun.net")
    html = response.read().decode('utf-8')
    print(html)
except urllib.error.URLError as e:
    print(f"Failed to reach the server: {e.reason}")
except urllib.error.HTTPError as e:
    print(f"Server couldn't fulfill the request: {e.code} - {e.reason}")
except Exception as e:
    print(f"An unexpected error occurred: {str(e)}")