Reputation: 2968
Script:
>>> import requests
>>> print(requests.head('https://knoema.com/BISDPPLS2016/bis-property-prices-long-series'))
<Response [200]>
>>> print(requests.head('https://beta.knoema.org/BISDPPLS2016/bis-property-prices-long-series'))
Connection to beta.knoema.org timed out.
I tried below as well, but same error:
>>> print(requests.head('https://beta.knoema.org/IRFCL2016Jul', timeout=5))
I want to stop requests.head(url)
if it does not exist or is not loading for any reason. How to achieve this?
Upvotes: 2
Views: 4297
Reputation: 9931
You have to handle exception using try-catch
try:
requests.head('https://beta.knoema.org/BISDPPLS2016/bis-property-prices-long-series')
except requests.exceptions.Timeout as e:
print e
Also you can set a large timeout to avoid error due to slow connection
requests.head('https://beta.knoema.org/BISDPPLS2016/bis-property-prices-long-series', \
timeout=5)
Here timeout is 5 seconds
Upvotes: 4