import time
import requests
import traceback
+import warnings
import docutils.core
import jinja2
"""Loads dict of current requirements or empty dict if file doesn't exist"""
url = 'https://onap.readthedocs.io/en/latest/_downloads/needs.json'
- r = requests.get(url)
- with open('requirements.json', 'wb') as needs:
- needs.write(r.content)
- path = "heat_requirements.json"
+
+ try:
+ r = requests.get(url)
+ if r.headers.get('content-type') == 'application/json':
+ with open('requirements.json', 'wb') as needs:
+ needs.write(r.content)
+ else:
+ warnings.warning("Unexpected content-type ({}) encountered downloading requirements.json, using last saved copy".format(r.headers.get('content-type')))
+ except requests.exceptions.RequestException as e:
+ warnings.warn("Error downloading latest JSON, using last saved copy.")
+ warnings.warn(UserWarning(e))
+ path = "requirements.json"
if not os.path.exists(path):
return {}
with io.open(path, encoding="utf8", mode="r") as f: