我尝试在python中使用urllib.request库来读取url。 但是shell中有很多错误。 我在此之后写了代码。
import urllib.request
req=urllib.request
req.urlopen("http://www.naver.com")
但是在此之后有一些错误。
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
req.urlopen("http://news.naver.com/")
File "C:\Users\kyu\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 162, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\kyu\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 465, in open
response = self._open(req, data)
File "C:\Users\kyu\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 483, in _open
'_open', req)
File "C:\Users\kyu\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 443, in _call_chain
result = func(*args)
File "C:\Users\kyu\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 1268, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "C:\Users\kyu\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 1243, in do_open
r = h.getresponse()
File "C:\Users\kyu\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 1174, in getresponse
response.begin()
File "C:\Users\kyu\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 282, in begin
version, status, reason = self._read_status()
File "C:\Users\kyu\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 251, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
怎么了? 我不知道为什么会这样 我使用python 3.5.1和windows8.1 64bit。