반응형
저는 Python을 처음 사용하고 비디오 자습서를 따르고 있습니다.
여기에 코드 스 니펫이 있습니다.
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)
내 브라우저에서 http://sixty-north.com/c/t.txt
에 액세스 할 수 있습니다.
그러나 명령 프롬프트에 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>
해결 방법
그러한 호스트가 없습니다 : sixty-north
. sixty-north
를 sixty-north.com
으로 바꿉니다 (참고 : 끝에있는 .com
).
참조 페이지 https://stackoverflow.com/questions/22150299
반응형
'파이썬' 카테고리의 다른 글
파이썬 Pandas DataFrame에서 쉼표가있는 숫자 문자열을 부동 소수점으로 변환 (0) | 2020.12.21 |
---|---|
파이썬 jinja2에서 for 루프를 어떻게 끊을 수 있습니까? (0) | 2020.12.21 |
파이썬 TypeError : length-1 배열 만 NUMPY를 사용하여 Python 스칼라로 변환 할 수 있습니다. (0) | 2020.12.21 |
파이썬 Python의 'in'연산자를 재정의 하시겠습니까? (0) | 2020.12.20 |
파이썬 Inserting a value into all possible locations in a list (0) | 2020.12.20 |
댓글