# Buggy code
def _get_handle(path, mode, encoding=None):
    if py3compat.PY3:  # pragma: no cover
        f = open(path, mode, encoding=encoding)
    else:
        f = open(path, mode)
    return f


# Traceback (UnicodeDecodeError)
In [9]: df = read_clipboard(header=None, sep='\s+')

In [10]: df
Out[10]: ---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
/Users/wesm/<ipython-input-10-7ed0097d7e9e> in <module>()
----> 1 df

/Users/wesm/code/repos/ipython/IPython/core/displayhook.pyc in __call__(self, result)
236             self.start_displayhook()
237             self.write_output_prompt()
--> 238             format_dict = self.compute_format_data(result)
239             self.write_format_data(format_dict)
240             self.update_user_ns(result)

/Users/wesm/code/repos/ipython/IPython/core/displayhook.pyc in compute_format_data(self, result)
148             MIME type representation of the object.
149         """
--> 150         return self.shell.display_formatter.format(result)
151
152     def write_format_data(self, format_dict):

/Users/wesm/code/repos/ipython/IPython/core/formatters.pyc in format(self, obj, include, exclude)
124                     continue
125             try:
--> 126                 data = formatter(obj)
127             except:
128                 # FIXME: log the exception

/Users/wesm/code/repos/ipython/IPython/core/formatters.pyc in __call__(self, obj)
445                 type_pprinters=self.type_printers,
446                 deferred_pprinters=self.deferred_printers)
--> 447             printer.pretty(obj)
448             printer.flush()
449             return stream.getvalue()

/Users/wesm/code/repos/ipython/IPython/lib/pretty.pyc in pretty(self, obj)
349             if hasattr(obj_class, '_repr_pretty_'):
350                 return obj_class._repr_pretty_(obj, self, cycle)
--> 351             return _default_pprint(obj, self, cycle)
352         finally:
353             self.end_group()

/Users/wesm/code/repos/ipython/IPython/lib/pretty.pyc in _default_pprint(obj, p, cycle)
469     if getattr(klass, '__repr__', None) not in _baseclass_reprs:
470         # A user-provided repr.
--> 471         p.text(repr(obj))
472         return
473     p.begin_group(1, '<')

/Users/wesm/code/pandas/pandas/core/frame.pyc in __repr__(self)
458                 self.info(buf=buf, verbose=self._verbose_info)
459             else:
--> 460                 self.to_string(buf=buf)
461                 value = buf.getvalue()
462                 if max([len(l) for l in value.split('\n')]) > terminal_width:

/Users/wesm/code/pandas/pandas/core/frame.pyc in to_string(self, buf, columns, col_space, colSpace, header, index, na_rep, formatters, float_format, sparsify, nanRep, index_names, justify, force_unicode)
1038                                            index_names=index_names,
1039                                            header=header, index=index)
-> 1040         formatter.to_string(force_unicode=force_unicode)
1041
1042         if buf is None:

/Users/wesm/code/pandas/pandas/core/format.pyc in to_string(self, force_unicode)
193
194             if self.index:
--> 195                 to_write.append(adjoin(1, str_index, *stringified))
196             else:
197                 to_write.append(adjoin(1, *stringified))

/Users/wesm/code/pandas/pandas/core/common.pyc in adjoin(space, *lists)
398     toJoin = zip(*newLists)
399     for lines in toJoin:
--> 400         outLines.append(''.join(lines))
401     return '\n'.join(outLines)
402

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1: ordinal not in range(128)

# Fixed code
def _get_handle(path, mode, encoding=None):
    if py3compat.PY3:  # pragma: no cover
        if encoding:
            f = open(path, mode, encoding=encoding)
        else:
            f = open(path, mode, errors="replace")
    else:
        f = open(path, mode)
    return f