urllib.error

地址栏错误

import urllib.request
import urllib.error
import urllib.parse
req = urllib.request.Request('http://www.mycodr.cn')
try:
    r = urllib.request.urlopen(req)
    print(r.read())
except urllib.error.URLError as e:
    print(e)
    print(e.reason)
---


[Errno 11001] getaddrinfo failed

编码错误

try:
    r = urllib.request.urlopen('https://www.douban.com/aba.html')
    print(r.read())
except urllib.error.HTTPError as e:
    print(e.code)
    print(e.read().decode())
---

    
404



    
    404 Not Found
    

 
    
豆瓣 douban

Not Found

你要的东西不在这, 到别处看看吧。

你可能感兴趣的:(urllib.error)