Python TimeoutError: [WinError 10060] A connection attempt failed

*爱你&永不变心* 提交于 2020-01-01 00:52:14

问题


I am trying to make a python program that checks to see if the cost has changed or not for a website. However, every time I run the code it comes up with this python error below and then I can not access the site on any devices in the house for a period of time without is saying 'This site can’t be reached the site took too long to respond.' Even though it doesn't load for me the website is still working

Code below

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')

The error I get is

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>

来源:https://stackoverflow.com/questions/46027404/python-timeouterror-winerror-10060-a-connection-attempt-failed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!