title: TypeError: a bytes-like object is required, not 'str' in python and CSV
body: <blockquote>
  <p>TypeError: a bytes-like object is required, not 'str'</p>
  </blockquote>
  <p>Getting the above error while executing below python code to save the HTML table data in CSV file. Don't know how to get rideup. Pls help me.</p>
  <pre><code>import csv
  import requests
  from bs4 import BeautifulSoup
  
  url='http://www.mapsofindia.com/districts-india/'
  response=requests.get(url)
  html=response.content
  
  soup=BeautifulSoup(html,'html.parser')
  table=soup.find('table', attrs={'class':'tableizer-table'})
  list_of_rows=[]
  for row in table.findAll('tr')[1:]:
      list_of_cells=[]
      for cell in row.findAll('td'):
          list_of_cells.append(cell.text)
      list_of_rows.append(list_of_cells)
  outfile=open('./immates.csv','wb')
  writer=csv.writer(outfile)
  writer.writerow([&quot;SNo&quot;, &quot;States&quot;, &quot;Dist&quot;, &quot;Population&quot;])
  writer.writerows(list_of_rows)
  </code></pre>
  <p>on above the last line.</p>