import hmac, base64, hashlib, urllib2
base = 'https://.......'
def makereq(key, secret, path, data):
hash_data = path + chr(0) + data
secret = base64.b64decode(secret)
sha512 = hashlib.sha512
hmac = str(hmac.new(secret, hash_data, sha512))
header = {
'User-Agent': 'My-First-test',
'Rest-Key': key,
'Rest-Sign': base64.b64encode(hmac),
'Accept-encoding': 'GZIP',
'Content-Type': 'application/x-www-form-urlencoded'
}
return urllib2.Request(base + path, data, header)
错误:文件“C:/Python27/btctest.py”,第 8 行,在 makereq hmac = str(hmac.new(secret, hash_data, sha512)) UnboundLocalError: 在赋值之前引用了局部变量 'hmac'
有人知道为什么吗?谢谢