Python urlopen 错误 [Errno 11001] getaddrinfo 失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22150299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 00:23:08  来源:igfitidea点击:

urlopen error [Errno 11001] getaddrinfo failed

pythonpython-3.x

提问by Null Reference

I'm new to python and I'm following a video tutorial.

我是 Python 新手,正在学习视频教程。

So here's the code snippet

所以这是代码片段

from urllib.request import urlopen
with urlopen('http://sixty-north/c/t.txt') as story:
    story_words = []
    for line in story:
        line_words = line.decode('utf-8').split()
        for word in line_words:
            story_words.append(word)

I'm able to access http://sixty-north.com/c/t.txtin my browser.

我可以http://sixty-north.com/c/t.txt在我的浏览器中访问。

However when I type this into command prompt: python words.pyI get this error:

但是,当我在命令提示符中键入以下内容时:出现python words.py此错误:

C:\New folder>python words.py
Traceback (most recent call last):
  File "C:\Python33\lib\urllib\request.py", line 1248, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "C:\Python33\lib\http\client.py", line 1065, in request
    self._send_request(method, url, body, headers)
  File "C:\Python33\lib\http\client.py", line 1103, in _send_request
    self.endheaders(body)
  File "C:\Python33\lib\http\client.py", line 1061, in endheaders
    self._send_output(message_body)
  File "C:\Python33\lib\http\client.py", line 906, in _send_output
    self.send(msg)
  File "C:\Python33\lib\http\client.py", line 844, in send
    self.connect()
  File "C:\Python33\lib\http\client.py", line 822, in connect
    self.timeout, self.source_address)
  File "C:\Python33\lib\socket.py", line 417, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "words.py", line 2, in <module>
    with urlopen('http://sixty-north/c/t.txt') as story:
  File "C:\Python33\lib\urllib\request.py", line 156, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Python33\lib\urllib\request.py", line 469, in open
    response = self._open(req, data)
  File "C:\Python33\lib\urllib\request.py", line 487, in _open
    '_open', req)
  File "C:\Python33\lib\urllib\request.py", line 447, in _call_chain
    result = func(*args)
  File "C:\Python33\lib\urllib\request.py", line 1274, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "C:\Python33\lib\urllib\request.py", line 1251, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 11001] getaddrinfo failed>

采纳答案by jfs

There is no such host: sixty-north. Replace sixty-northwith sixty-north.com(notice: .comat the end)

没有这样的主机:sixty-north。替换sixty-northsixty-north.com(注意:.com在最后)

回答by Ishaan Sharma

Change host: sixty-northwith sixty-north.comAnd also, Restart your Internet Connection. Your Internet is not working properly.

更改主持人:sixty-northsixty-north.com并且也重新启动您的Internet连接。您的互联网工作不正常。