add timeout to catalog pages

This commit is contained in:
Edward Betts 2019-09-29 21:46:39 +01:00
parent 42a8353ecc
commit 6eb79ccfd5

5
app.py
View file

@ -388,7 +388,7 @@ def get_catalog_page(property_id, value):
if os.path.exists(filename): if os.path.exists(filename):
html = open(filename).read() html = open(filename).read()
else: else:
r = requests.get(url, headers={'User-Agent': user_agent}) r = requests.get(url, headers={'User-Agent': user_agent}, timeout=2)
html = r.text html = r.text
open(filename, 'w').write(html) open(filename, 'w').write(html)
@ -429,6 +429,7 @@ def item_page(item_id):
catalog_url = first_datavalue(entity, 'P973') catalog_url = first_datavalue(entity, 'P973')
catalog = None catalog = None
try:
if 'P4704' in entity['claims']: if 'P4704' in entity['claims']:
saam_id = first_datavalue(entity, 'P4704') saam_id = first_datavalue(entity, 'P4704')
catalog = saam.get_catalog(saam_id) catalog = saam.get_catalog(saam_id)
@ -461,6 +462,8 @@ def item_page(item_id):
'institution': detail['label'], 'institution': detail['label'],
'description': description, 'description': description,
} }
except requests.exceptions.ReadTimeout:
pass
return render_template('item.html', return render_template('item.html',
qid=qid, qid=qid,