鱼C论坛

 找回密码
 立即注册
查看: 1206|回复: 4

[已解决]跟着视频中做的下载一只猫的图片,但是一直报错,求大佬解惑

[复制链接]
发表于 2021-3-19 10:52:06 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
这是视频中的代码
import urllib.request

response = urllib.request.urlopen('http://placekiten.com/g/200/300')
cat_img = response.read()

with open('cat_200_300.jpg','wb') as f:
    f.write(cat_img)
这是报错的
Traceback (most recent call last):
  File "E:\Users\ll\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 1346, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "E:\Users\ll\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "E:\Users\ll\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "E:\Users\ll\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "E:\Users\ll\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1010, in _send_output
    self.send(msg)
  File "E:\Users\ll\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 950, in send
    self.connect()
  File "E:\Users\ll\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 921, in connect
    self.sock = self._create_connection(
  File "E:\Users\ll\AppData\Local\Programs\Python\Python39\lib\socket.py", line 822, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "E:\Users\ll\AppData\Local\Programs\Python\Python39\lib\socket.py", line 953, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\Users\ll\AppData\Local\Programs\Python\Python39\p14_1.py", line 3, in <module>
    response = urllib.request.urlopen('http://placekiten.com/g/200/300')
  File "E:\Users\ll\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "E:\Users\ll\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 517, in open
    response = self._open(req, data)
  File "E:\Users\ll\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 534, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "E:\Users\ll\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 494, in _call_chain
    result = func(*args)
  File "E:\Users\ll\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 1375, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "E:\Users\ll\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 1349, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 11001] getaddrinfo failed>
最佳答案
2021-3-19 12:09:39
你的单词错了placekiten ——>placekitten
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-3-19 12:09:39 | 显示全部楼层    本楼为最佳答案   
你的单词错了placekiten ——>placekitten
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-3-19 12:27:31 | 显示全部楼层
你这个网址不能访问
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-3-19 12:32:27 | 显示全部楼层
你的网址中placekiten应该变成placekitten(1楼说的那个)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-3-19 15:34:55 | 显示全部楼层
私はり 发表于 2021-3-19 12:32
你的网址中placekiten应该变成placekitten(1楼说的那个)

哈哈哈,原来是这样,谢谢各位,是我粗心了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-1-16 08:13

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表