import hmac, base64, hashlib, urllib2base = '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”,makereq中的第8行,hmac = str(hmac.new(secret,hash_data,sha512))UnboundLocalError:分配前已引用局部变量“ hmac”有人知道为什么吗?谢谢
                    
                    
                3 回答
 
                    
                    
                            宝慕林4294392
                            
                                
                            
                        
                        
                                                
                    TA贡献2021条经验 获得超8个赞
您正在hmac函数范围内重新定义变量,因此import语句的全局变量不在函数范围内。重命名function-scopehmac变量应该可以解决您的问题。
添加回答
举报
0/150
	提交
		取消
	