title: UnboundLocalError: local variable … referenced before assignment
body: <pre><code>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)
  </code></pre>
  
  <p>Error:
     File "C:/Python27/btctest.py", line 8, in makereq
      hmac = str(hmac.new(secret, hash_data, sha512))
  UnboundLocalError: local variable 'hmac' referenced before assignment</p>
  
  <p>Somebody knows why? Thanks</p>