Convert API authorization using Python

In order to use Convert's API, developers would first need to connect and authorize themselves. The code below is an example of how this can be done using Python.

from datetime import datetime
import hmac
import hashlib
import base64
import requests
import binascii

ApplicationID = 'AAAAAAA'; #Replace it with your APP ID
ApplicationSecretKey = 'SSSSSSS'; #Replace it with your APP SECRET KEY

Expires = 30; # In seconds. Request lifetime. If your requests take much time, try to increase this value

RequestURL = "https://app.convert.com/api/v1/projects/";
RequestBody = '';

ExpiresTimestamp = int(datetime.now(tz=None).timestamp()) + Expires;

SignString = ApplicationID + "\n" + str(ExpiresTimestamp) + "\n" +RequestURL + "\n" +RequestBody;

message = bytes(SignString, 'utf-8')
secret = bytes(ApplicationSecretKey, 'utf-8')

signature = str(binascii.hexlify(hmac.new(secret, message, digestmod=hashlib.sha256).digest()),'ascii')
Authorization = "Convert-HMAC-SHA256 Signature=" + signature;

headers={"Expires": ExpiresTimestamp, "Convert-Authorization": Authorization, "Convert-Application-ID": ApplicationID}
r = requests.get(RequestURL,headers=headers)

print(r.json())