相关疑难解决方法(0)

UnboundLocalError:在赋值之前引用的局部变量....

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)
Run Code Online (Sandbox Code Playgroud)

错误:文件"C:/Python27/btctest.py",第8行,在makereq中hmac = str(hmac.new(secret,hash_data,sha512))UnboundLocalError:在赋值之前引用的局部变量'hmac'

有人知道为什么吗?谢谢

python python-2.7

4
推荐指数
2
解决办法
1万
查看次数

标签 统计

python ×1

python-2.7 ×1