Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
31 lines (23 sloc) 694 Bytes

Generating signed HMAC request with Python 3.x+

import time
import base64
import hmac
import requests
from hashlib import sha256
from uuid import uuid1

timestamp = int(time.time())
key = "API_KEY"
method = "GET"
nonce = str(uuid1())
secret = "API_SECRET

raw_payload = '{"method":\"%s\","x-prd-key":\"%s\","x-prd-nonce":\"%s\","x-prd-time":\"%i\"}' % (method.upper(), key, nonce, timestamp)

signature = base64.b64encode(, raw_payload.encode(), digestmod=sha256).digest())

headers = {
    "x-prd-key": key,
    "x-prd-time": timestamp,
    "x-prd-signature": signature,
    "x-prd-nonce": nonce

requests.request('GET', '/whoami', headers=headers)