Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Fix 403 error by using the existing, custom, HawkAuth class (#1001)
Browse files Browse the repository at this point in the history
The addition of the payload to the GET request was causing the API to return a 403 error. However, removing the payload caused an exception from the `requests_hawk` package, requiring a payload when `always_hash_content=True`. Instead, we were able to resolve the issue by using the custom HawkAuth class, which is also used elsewhere in the EMT application.
  • Loading branch information
oliverjwroberts authored Jul 31, 2024
1 parent b4757ef commit be67ec9
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions app/enquiries/common/datahub_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from datetime import date
from django.conf import settings
from django.forms.models import model_to_dict
from requests_hawk import HawkAuth

import app.enquiries.ref_data as ref_data
from app.enquiries.utils import get_oauth_payload
from app.enquiries.common.cache import cached_requests
from app.enquiries.common.hawk import HawkAuth

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -101,12 +101,9 @@ def fetch_metadata(name):
response = cached_requests.get(
url,
auth=HawkAuth(
id=settings.DATA_HUB_ENQUIRY_MGMT_HAWK_ID,
key=settings.DATA_HUB_ENQUIRY_MGMT_HAWK_SECRET_KEY,
api_id=settings.DATA_HUB_ENQUIRY_MGMT_HAWK_ID,
api_key=settings.DATA_HUB_ENQUIRY_MGMT_HAWK_SECRET_KEY,
),
# Add dummy data to avoid error: MissingContent payload content and/or
# content_type cannot be empty when always_hash_content is True
data={"data": name},
timeout=10,
)
response.raise_for_status()
Expand Down

0 comments on commit be67ec9

Please sign in to comment.