title: UnicodeDecodeError: 'utf8' codec can't decode byte 0xa5 in position 0: invalid start byte
body: <p>I am using <code>Python-2.6 CGI</code> scripts but found this error in server log while doing <code>json.dumps()</code>,</p>
  <pre><code>Traceback (most recent call last):
    File &quot;/etc/mongodb/server/cgi-bin/getstats.py&quot;, line 135, in &lt;module&gt;
      print json.dumps(​​__get​data())
    File &quot;/usr/lib/python2.7/json/__init__.py&quot;, line 231, in dumps
      return _default_encoder.encode(obj)
    File &quot;/usr/lib/python2.7/json/encoder.py&quot;, line 201, in encode
      chunks = self.iterencode(o, _one_shot=True)
    File &quot;/usr/lib/python2.7/json/encoder.py&quot;, line 264, in iterencode
      return _iterencode(o, 0)
  UnicodeDecodeError: 'utf8' codec can't decode byte 0xa5 in position 0: invalid start byte
  </code></pre>
  <p>​Here ,</p>
  <p><code>​__get​data()</code> function returns <code>dictionary {}</code> .</p>
  <p>Before posting this question I have referred <strong><a href="https://stackoverflow.com/questions/6180521/unicodedecodeerror-utf8-codec-cant-decode-bytes-in-position-3-6-invalid-dat">this</a></strong> of question os SO.</p>
  <hr />
  <h2>UPDATES</h2>
  <p>Following line is hurting JSON encoder,</p>
  <pre><code>now = datetime.datetime.now()
  now = datetime.datetime.strftime(now, '%Y-%m-%dT%H:%M:%S.%fZ')
  print json.dumps({'current_time': now}) # this is the culprit
  </code></pre>
  <p>I got a temporary fix for it</p>
  <pre><code>print json.dumps( {'old_time': now.encode('ISO-8859-1').strip() })
  </code></pre>
  <p>But I am not sure is it correct way to do it.</p>