def get_opa_res(self, token, path, method): """ Get allowed dataset result from OPA """ try: response = requests.post( settings.CANDIG_OPA_URL + "/v1/data/permissions/datasets", headers={"Authorization": f"Bearer {settings.CANDIG_OPA_SECRET}"}, json=self.get_request_body(token, path, method) ) response.raise_for_status() except requests.exceptions.RequestException: error_response = { "error": "This request failed because we are unable to retrieve necessary info \ related to your account. Please contact your system administrator \ for assistance." } response = HttpResponseForbidden(json.dumps(error_response)) response["Content-Type"] = "application/json" return ("error", response) allowed_datasets = response.json()["result"] return allowed_datasets