POST order , {"message":"invalid signature"}? , python

Try this:

import time
import base64
import hmac
import hashlib
import requests
import json

cbTime = str(int(time.time()))
cbPass = ‘x’
cbKey = ‘x’
cbSecret = ‘x==’
cbMeth = ‘POST’
cbPair = ‘X-Y’
cbPath = ‘/orders’
payload = {
‘profile_id’: cbKey,
‘product_id’: cbPair,
‘type’: ‘limit’,
‘side’: ‘sell’,
‘price’: ‘x’,
‘size’: ‘x’
}
body = json.dumps(payload)
cbMsg = ‘{}{}{}{}’.format(cbTime,cbMeth,cbPath,body)

key = base64.b64decode(cbSecret)
msg = cbMsg.encode(‘utf-8’)
ash = hmac.digest(key, msg, hashlib.sha256)
sig = base64.b64encode(ash).decode(‘utf-8’)

headers = {
‘Content-Type’: ‘application/json’,
‘CB-ACCESS-TIMESTAMP’: cbTime,
‘CB-ACCESS-KEY’: cbKey,
‘CB-ACCESS-PASSPHRASE’: cbPass,
‘CB-ACCESS-SIGN’: sig
}

url = ‘https://api.exchange.coinbase.com/orders
r = requests.post(url, body, headers=headers)

print()
print(cbMsg)
print()
print(sig)
print()
print(r.text)
print()