title: UnicodeDecodeError: 'utf8' codec can't decode byte 0xe9 in position 18: invalid continuation byte
body: <p>I'm trying to output a datetime column to json.But I'm getting this error in Python 2.7:</p>
  
  <pre><code>UnicodeDecodeError: 'utf8' codec can't decode byte 0xe9 in position 18: invalid continuation byte
  </code></pre>
  
  <p>This is a sample data:</p>
  
  <pre><code>&gt;&gt;&gt; data
              id impact_date             store     country  \
  0      6244543  2017-10-10  ARGENTINA   ARGENTINA
  1      6244544  2017-10-10  ARGENTINA   ARGENTINA
  2      6244545  2017-10-10  ARGENTINA   ARGENTINA
  3      6244546  2017-10-10  ARGENTINA   ARGENTINA
  </code></pre>
  
  <p>This is my code:</p>
  
  <pre><code>data = get_data(DB_ENGINE, MYSQL_USER, MYSQL_PASSWORD, MYSQL_HOST, MYSQL_PORT, MYSQL_DB, query)
  
  
  if filename:
      with open(filename, 'w+') as f: f.write(json.dumps(x,default=datetime_handler))
  
  def datetime_handler(x):
      if isinstance(x, datetime.datetime):
          #return unicode(x.strftime("%B %d, %Y"),errors="ignore")
          # return unicode(x.strftime("%B %d, %Y").encode('latin-1'),errors="ignore")
          return x.strftime("%B %d, %Y").encode('ISO-8859-1')
      else:
              return x
      raise TypeError("Unknown type")
  
  
  if filename:
      with open(filename, 'w+') as f: f.write(json.dumps(x,default=datetime_handler))
  </code></pre>
  
  <p>How can I fix this?</p>
  
  <p>EDIT</p>
  
  <p>The full traceback:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;stdin&gt;", line 2, in &lt;module&gt;
    File "/usr/lib64/python2.7/json/__init__.py", line 250, in dumps
      sort_keys=sort_keys, **kw).encode(obj)
    File "/usr/lib64/python2.7/json/encoder.py", line 207, in encode
      chunks = self.iterencode(o, _one_shot=True)
    File "/usr/lib64/python2.7/json/encoder.py", line 270, in iterencode
      return _iterencode(o, 0)
  UnicodeDecodeError: 'utf8' codec can't decode byte 0xe9 in position 18: invalid continuation byte
  </code></pre>