title: Python HMAC: TypeError: character mapping must return integer, None or unicode
body: <p>I am having a slight problem with HMAC. When running this piece of code:</p>
  
  <pre><code>signature = hmac.new(
      key=secret_key,
      msg=string_to_sign,
      digestmod=sha1,
  )
  </code></pre>
  
  <p>I get a strange error:</p>
  
  <pre><code>  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hmac.py", line 133, in new
      return HMAC(key, msg, digestmod)
    File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hmac.py", line 72, in __init__
      self.outer.update(key.translate(trans_5C))
  TypeError: character mapping must return integer, None or unicode
  </code></pre>
  
  <p>When I print string_to_sign, it is a proper string like this:</p>
  
  <pre><code>GET
  \n
  \n
  application/json
  \n
  \n
  \n
  </code></pre>
  
  <p>What does the error mean? Is it because of new lines?</p>