我正在尝试为 API 调用创建签名 - 文档提供了以下说明:
timestamp = str(int(time.time()))
message = timestamp + request.method + request.path_url + (request.body or '')
signature = hmac.new(self.secret_key, message, hashlib.sha256).hexdigest()
但是,我总是收到此错误:
Exception has occurred: TypeError key: expected bytes or bytearray, but got 'str'
File "/Users/dylanbrandonuom/BouncePay_Code/src/coinbase/Coinbase_API.py", line 26, in __call__
signature = hmac.new(self.secret_key, message, hashlib.sha256).hexdigest()
File "/Users/dylanbrandonuom/BouncePay_Code/src/coinbase/Coinbase_API.py", line 40, in <module>
r = requests.get(api_url + 'user', auth=auth)
我尝试过改变
signature = hmac.new(self.secret_key, message, hashlib.sha256).hexdigest()
to
signature = hmac.new(b'self.secret_key', message, hashlib.sha256).hexdigest()
但没有成功。
这是错误的第二部分:
api_url = 'https://api.coinbase.com/v2/'
auth = CoinbaseWalletAuth(API_KEY, API_SECRET)
r = requests.get(api_url + 'user', auth=auth)
有谁能让我知道为什么这种情况不断发生?
我想这可能是消息变量request.method
and request.path_url
,但我不确定。