title: TypeError: a bytes-like object is required, not 'str' – Saving JSON data in Python
body: <p>I am getting data from twitter in json format and storing the same in a file.</p>
  
  <pre><code>consumer_key = 'Consumer KEY'
  consumer_secret = 'Secret'
  access_token = 'Token'
  access_secret = 'Access Secret'
  
  auth = OAuthHandler(consumer_key, consumer_secret)
  
  auth.set_access_token(access_token, access_secret)
  
  api = tweepy.API(auth)
  
  os.chdir('Path')
  file = open('TwData.json','wb')
  
  for status in tweepy.Cursor(api.home_timeline).items(15):
      simplejson.dump(status._json,file,sort_keys = True)
  file.close
  </code></pre>
  
  <p>But I am getting the below error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;stdin&gt;", line 2, in &lt;module&gt;
    File "/Users/abc/anaconda/lib/python3.6/json/__init__.py", line 180, in dump
      fp.write(chunk)
  TypeError: a bytes-like object is required, not 'str'
  </code></pre>