pender / chatbot-rnn

A toy chatbot powered by deep learning and trained on data from Reddit
MIT License
899 stars 370 forks source link

Pickle TypeError: a bytes-like object is required, not 'str' #31

Closed MauryaRitesh closed 6 years ago

MauryaRitesh commented 6 years ago

Getting this error: Traceback (most recent call last): File "chatbot.py", line 301, in main() File "chatbot.py", line 35, in main sample_main(args) File "chatbot.py", line 60, in sample_main saved_args = cPickle.load(f) TypeError: a bytes-like object is required, not 'str'

ButterscotchV commented 6 years ago

Googling the error would get the answer quickly, but because you asked it here I might as well give you the answer.

with open(config_path) as f:
    saved_args = cPickle.load(f)

should be

with open(config_path, 'rb') as f:
    saved_args = cPickle.load(f)

You should do the same for any other times this error appears. For some explanation, this will make cPickle load the file as a byte object instead of String, as rb stands for Read Binary.

Sources:

MauryaRitesh commented 6 years ago

That wasn't a solution I was looking for. Actually, there is not any module named cPickle, instead I tried _Pickle, that worked, but even I had a lot of errors in your code. So, I'm gonna create my own chatbot and soon I'll post a link to that to you. Thanks for your reply.

ButterscotchV commented 6 years ago

I used the module pickle and that worked with what I gave. Anyways, glad to see that you got it working, sorry if I may have sounded rude while giving my response, I was pretty tired.

P.S. this isn't my project ;)

Malithi-gif commented 3 years ago

Can load the file as below code? cs = pickle.load(open(it_path))

It gives the pickle TypeError: a bytes-like object is required, not 'str'