title: UnicodeDecodeError with the sys.stdout inside traceback.print_exc()
body: <p>I am getting <code>UnicodeDecodeError</code> with the <code>traceback.print_exc(file=sys.stdout)</code>. I am using Python3.4 and did not get the problem with Python2.7. </p>
  
  <p>Am I missing something here? How can I make sure that <code>sys.stdout</code> passes the correct encoded/decoded to the <code>traceback.print_exc()</code> ?</p>
  
  <p>My code looks something similar to this:</p>
  
  <pre><code>try:
      # do something which might throw an exception
  except Exception as e:
      # do something
      traceback.print_exc(file=sys.stdout) # Here I am getting the error
  </code></pre>
  
  <p>Error log:</p>
  
  <pre><code>  traceback.print_exc(file=sys.stdout)
    File "C:\Python34\lib\traceback.py", line 252, in print_exc
      print_exception(*sys.exc_info(), limit=limit, file=file, chain=chain)
    File "C:\Python34\lib\traceback.py", line 169, in print_exception
      for line in _format_exception_iter(etype, value, tb, limit, chain):
    File "C:\Python34\lib\traceback.py", line 153, in _format_exception_iter
      yield from _format_list_iter(_extract_tb_iter(tb, limit=limit))
    File "C:\Python34\lib\traceback.py", line 18, in _format_list_iter
      for filename, lineno, name, line in extracted_list:
    File "C:\Python34\lib\traceback.py", line 65, in _extract_tb_or_stack_iter
      line = linecache.getline(filename, lineno, f.f_globals)
    File "C:\Python34\lib\linecache.py", line 15, in getline
      lines = getlines(filename, module_globals)
    File "C:\Python34\lib\linecache.py", line 41, in getlines
      return updatecache(filename, module_globals)
    File "C:\Python34\lib\linecache.py", line 127, in updatecache
      lines = fp.readlines()
    File "C:\Python34\lib\codecs.py", line 313, in decode
      (result, consumed) = self._buffer_decode(data, self.errors, final)
  UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe7 in position 5213: invalid continuation byte
  </code></pre>