title: How do I encode and decode an entire dictionary python
body: <pre><code>  def userCheck(user):
      with open('newpass.txt', 'r+') as new:
        file = new.read()
      dict = json.loads(file)
      if user in dict:
        return True
      else:
        with open('newpass.txt', 'r+') as new:
          file = new.read()
          dictNew = json.loads(file)
          dictNew[user] = ''
          new.truncate(0)
          new.seek(0)
          new.write(base64.b64encode(bytes(json.dumps(dictNew))))
        with open('oldpass.txt', 'r+') as old:
          file = old.read()
          dictOld = json.loads(file)
          dictOld[user] = []
          old.truncate(0)
          old.seek(0)
          old.write(base64.b64encode(bytes(json.dumps(dictOld))))
        return False
  </code></pre>
  <p>using this method to encode the dictionary returns this error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;main.py&quot;, line 136, in &lt;module&gt;
      PassReset()
    File &quot;main.py&quot;, line 106, in PassReset
      if userCheck(username) == True:
    File &quot;main.py&quot;, line 20, in userCheck
      new.write(base64.b64encode(bytes(json.dumps(dictNew))))
  TypeError: string argument without an encoding
  </code></pre>
  <p>how would I go about encoding the entire thing using base 64 and json?
  This is my first time using base64 and I'm also relatively new to json so apologies.</p>