def handle_dotio_url(wf_module, url, split_url, num_rows):
"""
Processes response for any request to enigma.io. Here, we assume that the API key is provided,
because, at least at first glance (or two or three) there doesn't seem to be any provisions for
accessing dataset endpoints sans API key.
"""
if num_rows > 500:
wf_module.set_error("You can request a maximum of 500 rows.")
return
if "/limit/" not in url:
if url.endswith('/'):
url += "limit/{}".format(num_rows)
else:
url += "/limit/{}".format(num_rows)
response = requests.get(url)
if response.status_code != 200:
error = json.loads(response.text)
if "message" in error:
message = error["message"]
else:
message = error["info"]["message"]
if "additional" in error["info"]:
message += ": " + error["info"]["additional"]["message"]
wf_module.set_error("Unable to retrieve data from Enigma. Received {} status, with message {}"
.format(response.status_code, message))
return
try:
json_text = json.loads(response.text)
table = pd.read_json(json.dumps(json_text['result']))
return table
except Exception as ex: # Generic exceptions suck, but is it the most pragmatic/all-encompassing here?
wf_module.set_error("Unable to process request: {}".format(str(ex)))
return
评论列表
文章目录