ADD: informative error message for sentiment_hq API, testing

This commit is contained in:
Madison May
2015-06-11 18:13:15 -04:00
parent 47133c956f
commit 91b7bfd454
2 changed files with 29 additions and 6 deletions
+8 -6
View File
@@ -22,15 +22,17 @@ def api_handler(arg, cloud, api, url_params = {"batch":False, "api_key":None}, *
# default to indico public cloud
host = config.PUBLIC_API_HOST
# error message for public cloud
if api == 'sentimenthq':
raise IndicoError("The high quality sentiment API is currently in private beta.")
url = config.url_protocol + "//%s/%s" % (host, api)
url = url + "/batch" if url_params.get("batch", False) else url
url += "?key=%s" % (url_params.get("api_key", None) or config.api_key)
if "apis" in url_params:
url += "&apis=%s" % ",".join(url_params["apis"])
apis = url_params.get("apis", [])
if apis:
url += "&apis=%s" % ",".join(apis)
# private beta
if host == config.PUBLIC_API_HOST:
if (api == 'sentimenthq') or ('sentimenthq' in apis):
raise IndicoError("The high quality sentiment API is currently in private beta.")
response = requests.post(url, data=json_data, headers=JSON_HEADERS)
if response.status_code == 503 and cloud != None: