title: Read Fernet Key Causes ValueError: Fernet key must be 32 url-safe base64-encoded bytes
body: <p>In this function I am trying to read a Fernet key from a file, or create one if the file doesn't contain a key.</p>
  
  <pre><code>from cryptography.fernet import Fernet
  import csv
  
  
  with open("Keys.txt","rU") as csvfile:
      reader=csv.reader(csvfile)
      KeyFound=0
      print(KeyFound)
      for row in reader:
          try:
              print(row[0])
          except IndexError:
              continue
          if len(row[0])&gt;4:
              print("KEY FOUND")
              KeyFound=1
              print(KeyFound)
              Key=row[0]
              print(Key)
              print(KeyFound)
          else:
              pass
  if KeyFound==0:
      Key = Fernet.generate_key()
      print(Key)
      print("Created Key")
      csvfile.close()
  #Writing Key to textfile
  with open("Keys.txt", "w+") as csvfile:
      headers = ['key']
      writer=csv.DictWriter(csvfile, fieldnames=headers)
      writer.writeheader()
      writer.writerow({'key': Key})
      csvfile.close()
  print(Key)
  Ecy = Fernet(Key)
  </code></pre>
  
  <p>I am having difficulty reading the file. When the file is read the key is read in as:</p>
  
  <pre><code>b'nNjpIl9Ax2LRtm-p6ryCRZ8lRsL0DtuY0f9JeAe2wG0='
  </code></pre>
  
  <p>Yet I receive this error:</p>
  
  <pre><code>ValueError: Fernet key must be 32 url-safe base64-encoded bytes.
  </code></pre>
  
  <p>In this line:</p>
  
  <pre><code>Ecy = Fernet(Key)
  </code></pre>
  
  <p>Any help would be appreciated.</p>