title: How do I resolves the Fernet key error in python?
body: <p>I am trying to encrypt Passwords but the function below</p>
  <pre><code>def Get_En_PassID():
  
      Filename = 'Login_Token.bin'
      if os.path.exists(Filename):
          with open(Filename, 'rb') as file_object:
              for line in file_object:
                  encryptedpwd = line.decode('utf-8')
                  key = encryptedpwd
                  print(key)
              #return encryptedpwd
         
          
      else:
          PW = &quot;encrypted message&quot;
          cipher_suite = Fernet(Fernet.generate_key())
          #ciphered_text = cipher_suite.encrypt(bytes(PW,'utf-8'))   #required to be bytes
          ciphered_text = cipher_suite.encrypt(PW.encode('utf-8'))   #required to be bytes
          with open(Filename, 'wb') as file_object:  file_object.write(ciphered_text)
          key = ciphered_text    
          #return ciphered_text
  
          
      f = Fernet(key)
      p = f.decrypt(key)
      
  
      print(p)
  </code></pre>
  <p>only returning <code>ValueError: Fernet key must be 32 url-safe base64-encoded bytes.</code>
  Can you tell me what I'm doing wrong?
  I've seen a different question with similar problem and I've tried it but it's still giving this error</p>
  <p>the token that's in the file : <code>gAAAAABfpT0o0lcFJnvTUFmPvwEnrkX7-PK2Bs4t---QDK...b7XdJEr40nJnFAfNM=</code></p>