Skip to content
Home » TypeError: must be str not bytes with pickle.dump()

TypeError: must be str not bytes with pickle.dump()

To solve TypeError: must be str not bytes with pickle.dump() error follow below methods. Refer the error log below.

ERROR LOG

File "C:/Python2/program.py", line 6
    pickle.dump(vdict,f,)
TypeError: must be str, not bytes

How to solve Using pickle.dump – TypeError: must be str, not bytes ?

The output file or the file to which you are saving your model is to be opened in binary mode i.e 'wb'.

f = open('varstor.txt','wb')

In Python 3, the binary modes ‘wb’ and ‘rb’ must be given, whereas they are not required in Python 2x. You’ve arrived here because you’ve been following Python 2x tutorials.

Hope the above solution works.

Also read : ValueError: unsupported format character while forming strings