Rohit
Rohit

Reputation: 7161

Using Python 3.5, throwing error: TypeError: a bytes-like object is required, not 'str'

I am using Spyder Python IDE, Python version 3.5 and trying to run this python file having code

import pickle

enron_data = pickle.load(open("../final_project/final_project_dataset.pkl", "r"))

However on running, it throws following error

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

Upvotes: 1

Views: 1732

Answers (1)

hiro protagonist
hiro protagonist

Reputation: 46901

you need to open your file in binary (so read it returns bytes and not str):

open("../final_project/final_project_dataset.pkl", "rb")

(note the additional 'b' in the mode).

Upvotes: 3

Related Questions