title: How to encode a unicode string (ones from JSON) to 'utf-8' in python?
body: <p>I am creating a REST API using Flask-Python. One of the urls (/uploads) takes in (a POST HTTP request) and a JSON '{"src":"void", "settings":"my settings"}'. I can individually extract each object and encode to a byte string which can then be hashed using hashlib in python. However, my goal is to take the whole string and then encode so it looks like...myfile.encode('utf-8'). Printing myfile displays as follows >> {u'src':u'void', u'settings':u'my settings'}, is there anyway I can take the above unicoded string then encode to utf-8 to a sequence of bytes for hashlib.sha1(mayflies.encode('uff-8'). Do let me know for more clarification. Thanks in advance.</p>
  
  <pre><code>fileSRC = request.json['src']
  fileSettings = request.json['settings']
  
  myfile = request.json
  print myfile
  
  #hash the filename using sha1 from hashlib library
  guid_object = hashlib.sha1(fileSRC.encode('utf-8')) // this works however I want myfile to be encoded not fileSRC
  guid = guid_object.hexdigest() //this works 
  print guid
  </code></pre>