Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MauryaRitesh opened this issue Nov 25, 2017 · 4 comments
Closed

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

MauryaRitesh opened this issue Nov 25, 2017 · 4 comments

Comments

@MauryaRitesh
Copy link

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
Copy link

ButterscotchV commented Nov 25, 2017

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
Copy link
Author

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
Copy link

ButterscotchV commented Nov 26, 2017

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
Copy link

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants