|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- urllib.error.URLError: <urlopen error [Errno 11001] getaddrinfo failed>
复制代码
- import urllib.request
- req = urllib.request.Request("http://placekittrn.com/g/500/600")
- response = urllib.request.urlopen(req)
- cat_img = response.read().decode('utf-8')
- with open('cat_500_600.jpg','wb') as f:
- f.write(cat_img)
复制代码
网址错了是:placekitten,不是placekittrn
而且代码中 decode 需要去掉,参考代码:
- import urllib.request
- req = urllib.request.Request("http://placekitten.com/g/500/600")
- response = urllib.request.urlopen(req)
- cat_img = response.read()
- with open('cat_500_600.jpg','wb') as f:
- f.write(cat_img)
复制代码
|
|