I'm trying to create an HMAC-SHA512 signed request for an API call in Python 3.4 using the requests library. I'm trying to follow docs, but am hitting this error:
AttributeError: '_hashlib.HASH' object has no attribute 'new'
Here's some code. It's failing with the error on the hmac constructor. It's fine if I try and pass hashlib.md5() or omit the digest parameter entirely.
I'm not sure if I'm signing the request properly afterwards as I haven't got that far yet. The docs for the service I'm trying to use say to sign the URL with my secret. I need this to be a byte string for this to work.
import hmac
import hashlib
import requests
secret = b'mysecret'
url = b'http://someurl.com/something/'
signing = hmac.new(secret, url, hashlib.sha512())
headers = {'apisign': signing.digest()}
response = requests.get(url, headers=headers)
Any pointers appreciated. I couldn't find an example. Thanks!