requests-hawk

raw JSON →
1.2.1 verified Fri May 01 auth: no python maintenance

A requests authentication plugin that implements the Hawk HTTP authentication scheme (https://github.com/hueniverse/hawk). Provides request signing and verification for HTTP APIs. Current version 1.2.1, last updated 2019. Maintenance mode, no recent releases.

pip install requests-hawk
error ImportError: No module named requests_hawk
cause Library not installed or environment issue
fix
Run 'pip install requests-hawk' and ensure it's in the same Python environment.
error TypeError: __init__() got an unexpected keyword argument 'hawk_credentials'
cause Incorrect argument name; should be 'hawk_credentials' (singular) not 'hawk_credentials'.
fix
Use 'hawk_credentials' as the parameter name.
error mohawk.exceptions.MissingRequiredAttribute: payload can't be blank when hash is required
cause The request has a body but Content-Type is missing or empty; Hawk requires hash for non-empty payloads.
fix
Ensure requests have a Content-Type header set (e.g., 'Content-Type': 'application/json') when sending data.
deprecated Library is in maintenance mode. No active development since 2019. Consider using 'mohawk' directly or 'requests-hawk' as-is.
fix Monitor for vulnerabilities; for new projects, evaluate using the 'mohawk' library with custom requests auth.
gotcha The hawk_credentials dict must contain 'id', 'key', and 'algorithm'. 'algorithm' defaults to 'sha256' but is recommended to be explicit.
fix Always include all three keys to avoid confusion.
gotcha Content-Type handling changed in v1.1.1 when Content-Type is bytes. Ensure you send headers as strings or use latest version.
fix Upgrade to >=1.1.1 or ensure Content-Type is a string.

Create a HawkAuth instance with credentials and pass it as the 'auth' parameter to requests.

import requests
from requests_hawk import HawkAuth

auth = HawkAuth(
    hawk_credentials={
        'id': 'my-id',
        'key': 'my-secret-key',
        'algorithm': 'sha256'
    }
)
response = requests.get('https://example.com/api/resource', auth=auth)
print(response.status_code)