0

I'm trying to store a dictionary into a file.

This is part of my code:

Accounts={}
if username not in Accounts:
    Accounts[username]=password
    database=open("my_mail_database", "w")
     pickle.dump(Accounts, database)
     database.close()

And I always get this error:

Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1538, in __call__
return self.func(*args)
File "C:\Python34\python 3.4\my_gmail2.pyw", line 51, in submit_account
pickle.dump(Accounts, database)
TypeError: must be str, not bytes

Can someone tell me whats the problem with my code?

Daniel Engel
  • 158
  • 3
  • 13
  • 5
    http://stackoverflow.com/questions/13906623/using-pickle-dump-typeerror-must-be-str-not-bytes – zezollo Mar 21 '16 at 15:39

1 Answers1

1

Try that:

Accounts={}
if username not in Accounts:
    Accounts[username]=password
    database=open("my_mail_database", "wb")
    pickle.dump(Accounts, database)
    database.close()

You have to open file with wb

Alexey Smirnov
  • 2,573
  • 14
  • 20