title: Python; Encode to MD5 (hashlib) shows error: "NoneType"
body: <p>I wrote a code that will generate random password for 5 times, and I would like to encode that passwords to MD5, but when I try to encode it, it will show an error that 'NoneType' object has no attribute 'encode' and I dont know how to change the code to avoid this error. Sorry I'm beginner in python... My Code is below. Thanks for help </p>
  
  <pre><code>import random, string
  import hashlib
  
  length = 6
  chars = string.ascii_letters + string.digits
  
  def ff():
      rnd = random.SystemRandom()
      a = (''.join(rnd.choice(chars) for i in range(length)))
      c = a
      return(c)
  
  def ff2():
      for i in range(5):
          print(ff(),' ')
  
  
  str = ff2()
  result = hashlib.md5(str.encode())
  
  print("The hexadecimal equivalent of hash is : ", end ="")
  print(result.hexdigest())
  </code></pre>