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>