-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54372ef
commit cb9737e
Showing
2 changed files
with
28 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,32 @@ | ||
import os | ||
import flask | ||
import requests | ||
import json | ||
import traceback | ||
import logging | ||
|
||
# --------------------------------- | ||
# MOVE THIS TO REFERENCE FROM ENV | ||
# --------------------------------- | ||
DATASTORE_URL = os.environ.get("DATASTORE_URL","url not found") | ||
DATASTORE_URL = os.path.join(DATASTORE_URL, "api/") | ||
logger = logging.getLogger("imaging_app") | ||
|
||
# --------------------------------- | ||
# Get Data From datastore | ||
# --------------------------------- | ||
|
||
def get_api_data(api_address): | ||
class PortalAuthException(Exception): | ||
'''Custom Exception for issues with Authentication''' | ||
|
||
def get_api_data(api_address, ignore_cache=False): | ||
api_json = {} | ||
try: | ||
try: | ||
response = requests.get(api_address, cookies=flask.request.cookies) | ||
except Exception as e: | ||
return('error: {}'.format(e)) | ||
request_status = response.status_code | ||
if request_status == 200: | ||
api_json = response.json() | ||
return api_json | ||
else: | ||
return request_status | ||
params = {} | ||
if ignore_cache: | ||
params = {'ignore_cache':True} | ||
response = requests.get(api_address, params=params, cookies=flask.request.cookies) | ||
response.raise_for_status() | ||
return response.json() | ||
except Exception as e: | ||
traceback.print_exc() | ||
logger.warn(e) | ||
api_json['json'] = 'error: {}'.format(e) | ||
return api_json |