title: TypeError: a bytes-like object is required, not 'str' when opening Python 2 Pickle file in Python 3
body: <p>I am trying to open a pickle file in Python 3 with code that worked in Python 2 but is now giving me an error. Here is the code:</p>
  
  <pre><code>with open(file, 'r') as f:
      d = pickle.load(f)
  
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-25-38f711abef06&gt; in &lt;module&gt;()
        1 with open(file, 'r') as f:
  ----&gt; 2     d = pickle.load(f)
  
  TypeError: a bytes-like object is required, not 'str'
  </code></pre>
  
  <p>I saw on other SO answers that people had this problem when using <code>open(file ,'rb')</code> and switching to <code>open(file ,'r')</code> fixed it. If this helps, I tried <code>open(file ,'rb')</code> just to experiment and got the following error:</p>
  
  <pre><code>UnpicklingError                           Traceback (most recent call last)
  &lt;ipython-input-26-b77842748a06&gt; in &lt;module&gt;()
        1 with open(file, 'rb') as f:
  ----&gt; 2     d = pickle.load(f)
  
  UnpicklingError: invalid load key, '\x0a'.
  </code></pre>
  
  <p>When I open the file with <code>f = open(file, 'r')</code> and the enter <code>f</code> I get:</p>
  
  <pre><code>&lt;_io.TextIOWrapper name='D:/LargeDataSets/Enron/final_project_dataset.pkl' mode='r' encoding='cp1252'&gt;
  </code></pre>
  
  <p>So I also tried:</p>
  
  <pre><code>with open(file, 'rb') as f:
      d = pickle.load(f, encoding='cp1252')
  </code></pre>
  
  <p>and got the same error as with using 'rb':</p>
  
  <pre><code>UnpicklingError                           Traceback (most recent call last)
  &lt;ipython-input-27-959b1b0496d0&gt; in &lt;module&gt;()
        1 with open(file, 'rb') as f:
  ----&gt; 2     d = pickle.load(f, encoding='cp1252')
  
  UnpicklingError: invalid load key, '\x0a'.
  </code></pre>