2016-06-08 2 views
2

저는 컴퓨터에서 파이썬 2.7.10과 파이썬 3.4.4를 모두 실행하고 있습니다. 다음 코드는 파이썬 2.7.10에서 작동 :urlopen은 파이썬 2.7에서 작동하지만 파이썬 3.4에서는 실패합니다

import urllib2 
print urllib2.urlopen('http://google.com').read() 

을하지만, 내가 파이썬 3.4.4로 이동하고 내가 오류의 긴 쌍 얻을

import urllib.request 
print(urllib.request.urlopen('http://google.com').read()) 

실행하는 경우 :

Traceback (most recent call last): 
    File "C:\Python34\lib\urllib\request.py", line 1183, in do_open 
    h.request(req.get_method(), req.selector, req.data, headers) 
    File "C:\Python34\lib\http\client.py", line 1137, in request 
    self._send_request(method, url, body, headers) 
    File "C:\Python34\lib\http\client.py", line 1182, in _send_request 
    self.endheaders(body) 
    File "C:\Python34\lib\http\client.py", line 1133, in endheaders 
    self._send_output(message_body) 
    File "C:\Python34\lib\http\client.py", line 963, in _send_output 
    self.send(msg) 
    File "C:\Python34\lib\http\client.py", line 898, in send 
    self.connect() 
    File "C:\Python34\lib\http\client.py", line 871, in connect 
    self.timeout, self.source_address) 
    File "C:\Python34\lib\socket.py", line 516, in create_connection 
    raise err 
    File "C:\Python34\lib\socket.py", line 507, in create_connection 
    sock.connect(sa) 
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "<pyshell#17>", line 1, in <module> 
    print(urllib.request.urlopen('http://google.com').read()) 
    File "C:\Python34\lib\urllib\request.py", line 161, in urlopen 
    return opener.open(url, data, timeout) 
    File "C:\Python34\lib\urllib\request.py", line 464, in open 
    response = self._open(req, data) 
    File "C:\Python34\lib\urllib\request.py", line 482, in _open 
    '_open', req) 
    File "C:\Python34\lib\urllib\request.py", line 442, in _call_chain 
    result = func(*args) 
    File "C:\Python34\lib\urllib\request.py", line 1211, in http_open 
    return self.do_open(http.client.HTTPConnection, req) 
    File "C:\Python34\lib\urllib\request.py", line 1185, in do_open 
    raise URLError(err) 
urllib.error.URLError: <urlopen error [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond> 

이 같은 오류가 here (저는 Windows 7을 실행 중입니다)과 같이 Windows 설정에 문제가 있음을 알았지 만 이해할 수없는 것은 2.7에서 작동하고 3.4에서 작동하지 않습니다.

+1

패키지 이름을 변경했다고 생각합니다 ... – linusg

+2

권장 사항 : [요청] (http://docs.python-requests.org/ko/master/)을 사용하십시오. – Kupiakos

+0

GNU/Linux에서 Python 3.2.3을 사용하면 정상적으로 작동합니다. 아마도 Windows 컴파일 문제는 ... –

답변

0

솔루션에서 작업 한 후 Python 2.7 코드에서 동일한 오류가 발생하기 시작했습니다. 좌절에서 나는 마이크로 스코프 픽스를 적용하기 시작했다. 로그 오프하고 다시 로그인하여 시작했습니다. 모든 것이 이제 의도대로 작동합니다 ...

관련 문제