title: Python unicode object must be encoded before hashing
body: <p>I am trying to hash some random string:</p>
  
  <pre><code>key = ''.join(random.choice(string.ascii_lowercase) for i in range(10))
  salt = hashlib.sha1(key).hexdigest()[:5].encode('utf-8')            
  activation_key = hashlib.sha1(salt+email).hexdigest() 
  </code></pre>
  
  <p>When I do this it says unicode object must be encoded before hashing:</p>
  
  <pre><code>Traceback (most recent call last):
    # lines omitted..
    File &lt;something&gt;, line &lt;digits&gt;, in &lt;module name&gt;
      salt = hashlib.sha1(key).hexdigest()[:5].encode('utf-8')            
  TypeError: Unicode-objects must be encoded before hashing
  </code></pre>
  
  <p>Whats wrong in here? I have even encoded key.</p>