r/MicroPythonDev • u/TheRealMatt6079 • Feb 02 '23
Hmac and base64 on micropython rp2040 ?
I was trying to convert this code to work on a Raspberry Pi Pico with Micropython 1.19
api_key = "api_key"
api_secret = "api_secret"
api_passphrase = "api_passphrase"
url = 'https://openapi-sandbox.kucoin.com/api/v1/accounts'
now = int(time.time() * 1000)
str_to_sign = str(now) + 'GET' + '/api/v1/accounts'
signature = base64.b64encode(
hmac.new(api_secret.encode('utf-8'), str_to_sign.encode('utf-8'), hashlib.sha256).digest())
passphrase = base64.b64encode(hmac.new(api_secret.encode('utf-8'), api_passphrase.encode('utf-8'), hashlib.sha256).digest())
headers = {
"KC-API-SIGN": signature,
"KC-API-TIMESTAMP": str(now),
"KC-API-KEY": api_key,
"KC-API-PASSPHRASE": passphrase,
"KC-API-KEY-VERSION": "2"
}
response = requests.request('get', url, headers=headers)
print(response.status_code)
print(response.json())Hmac and base64 don't appear to be available to me, any way round it?
ps. It's the KuCoin API I'm trying to connect to, if there's an existing micropython library that'd be great but I couldn't find one.
1
Upvotes
View all comments
Show parent comment
2
u/TheRealMatt6079 Feb 16 '23
Thanks, really handy guide. I'm going to try and get back to this at the weekend.
I'll build my own :)