在windows下写了个python爬虫,发现一运行就出现
Traceback (most recent call last):
File "D:\Program Files\python\lib\urllib\request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "D:\Program Files\python\lib\http\client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "D:\Program Files\python\lib\http\client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "D:\Program Files\python\lib\http\client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "D:\Program Files\python\lib\http\client.py", line 1026, in _send_output
self.send(msg)
File "D:\Program Files\python\lib\http\client.py", line 964, in send
self.connect()
File "D:\Program Files\python\lib\http\client.py", line 936, in connect
(self.host,self.port), self.timeout, self.source_address)
File "D:\Program Files\python\lib\socket.py", line 722, in create_connection
raise err
File "D:\Program Files\python\lib\socket.py", line 713, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/apersonlikep/Desktop/testspider2.py", line 61, in <module>
use_proxy(url)
File "C:/Users/apersonlikep/Desktop/testspider2.py", line 8, in use_proxy
html = urllib.request.urlopen(req).read().decode('utf-8')
File "D:\Program Files\python\lib\urllib\request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "D:\Program Files\python\lib\urllib\request.py", line 526, in open
response = self._open(req, data)
File "D:\Program Files\python\lib\urllib\request.py", line 544, in _open
'_open', req)
File "D:\Program Files\python\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "D:\Program Files\python\lib\urllib\request.py", line 1346, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "D:\Program Files\python\lib\urllib\request.py", line 1320, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [WinError 10061] 由于目标计算机积极拒绝,无法连接。>
但是我在linux的虚拟机上可以跑,实在不知道为什么
网上找说开了代理,但是我没开代理,
其次我防火墙也关了试过,还是不行