2017-09-03 2819 views
0

我想做一个python程序,检查成本是否已经改变或不是一个网站。但是,每次运行代码时,都会出现下面的python错误,然后我无法在一段时间内访问该网站上的任何设备,而没有说“该网站无法访问渴望回应。“ 即使它不会加载我的网站仍在工作Python的超时错误:[WinError 10060]连接尝试失败

代码如下

try: 
from urllib.request import urlopen 
import smtplib 
import time 
except ImportError: 
# Fall back to Python 2's urllib2 
from urllib2 import urlopen 

ufo = urlopen("https://www.tinydeal.com/mystery-floating-ufo-flying-saucer- 
frisbee-magic-trick-toy-p-157394.html") 
time.sleep(5) 

knife = urlopen("https://www.tinydeal.com/3-in-1-paring-knife-slicer-triple- 
fruit-vegetable-cooking-tool-p-163606.html") 
time.sleep(5) 

mosquito = urlopen("https://www.tinydeal.com/2-in-1-mosquito-killer-lamp- 
led-night-light-romantic-sleeping-lamp-p-160265.html") 
time.sleep(5) 

lenovocase = urlopen("https://www.tinydeal.com/soft-silicone-frosted-back- 
case-for-lenovo-vibe-shot-z90-7-p-159210.html") 
time.sleep(5) 

cereal = urlopen("https://www.tinydeal.com/cereal-double-dispenser-machine- 
breakfast-food-storage-container-p-167155.html") 
time.sleep(5) 

onion = urlopen("https://www.tinydeal.com/onion-goggles-cutting-onion- 
glasses-bbq-eye-protective-anti-spicy-no-tears-p-167156.html") 

print('Have they changed price?\n') 
print ('Mystery Floating UFO Flying Saucer Frisbee Magic Trick') 
if ufo == '£1.07': 
print ('yes') 
else: 
print ('no') 

print ('3-in-1 knife') 
if knife == '£2.31': 
print ('yes') 
else: 
print ('no') 

print ('mosquito') 
if mosquito == '£3.85': 
print ('yes') 
else: 
print ('no') 

print ('lenovo case') 
if lenovocase == '£0.69': 
print ('yes') 
else: 
print ('no') 

print ('cereal') 
if cereal == '£13.88': 
print ('yes') 
else: 
print ('no') 

print ('onion goggles') 
if onion == '£2.31': 
print ('yes') 
else: 
print ('no') 

我得到的错误是

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 1279, in connect 
super().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 "C:\Users\Ollie\Desktop\g2.py", line 12, in <module> 
knife = urlopen("https://www.tinydeal.com/3-in-1-paring-knife-slicer-triple- 
fruit-vegetable-cooking-tool-p-163606.html") 
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 1226, in https_open 
context=self._context, check_hostname=self._check_hostname) 
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>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 1279, in connect 
super().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 "C:\Users\Ollie\Desktop\g2.py", line 12, in <module> 
knife = urlopen("https://www.tinydeal.com/3-in-1-paring-knife-slicer-triple- 
fruit-vegetable-cooking-tool-p-163606.html") 
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 1226, in https_open 
context=self._context, check_hostname=self._check_hostname) 
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>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 1279, in connect 
super().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 "C:\Users\Ollie\Desktop\g2.py", line 12, in <module> 
knife = urlopen("https://www.tinydeal.com/3-in-1-paring-knife-slicer-triple- 
fruit-vegetable-cooking-tool-p-163606.html") 
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 1226, in https_open 
context=self._context, check_hostname=self._check_hostname) 
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> 

回答

相关问题