python error:[Error 10061]
刚刚开始学用Python写爬虫,按照教程写了第一个程序:
# -*- coding: UTF-8 -*-
import urllib
def demo():
s = urllib.urlopen('http://www.baidu.com')#返回一个类文件
print(s.read(100))#读取100个字节并输出
if __name__ == '__main__':
demo()
输出以下错误,上网搜索了Traceback (most recent call last)和error10061的解决办法,但是依然没有解决,希望大家能帮帮忙。
C:\Python27\python.exe C:/pythonProjects/urllib_demo.py
Traceback (most recent call last):
File "C:/pythonProjects/urllib_demo.py", line 10, in <module>
demo()
File "C:/pythonProjects/urllib_demo.py", line 6, in demo
s = urllib.urlopen('http://www.baidu.com')#返回一个类文件
File "C:\Python27\lib\urllib.py", line 87, in urlopen
return opener.open(url)
File "C:\Python27\lib\urllib.py", line 213, in open
return getattr(self, name)(url)
File "C:\Python27\lib\urllib.py", line 350, in open_http
h.endheaders(data)
File "C:\Python27\lib\httplib.py", line 1038, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 882, in _send_output
self.send(msg)
File "C:\Python27\lib\httplib.py", line 844, in send
self.connect()
File "C:\Python27\lib\httplib.py", line 821, in connect
self.timeout, self.source_address)
File "C:\Python27\lib\socket.py", line 575, in create_connection
raise err
IOError: [Errno socket error] [Errno 10061]
Process finished with exit code 1