(data, name='data')
Call data.encode("latin-1") but show a better error message.
Call data.encode("latin-1") but show a better error message.
Call data . encode ( latin - 1 ) but show a better error message .
def _encode(data, name='data'):
    """Call data.encode("latin-1") but show a better error message."""
    try:
        return data.encode("latin-1")
    except UnicodeEncodeError as err:
        raise UnicodeEncodeError(
            err.encoding,
            err.object,
            err.start,
            err.end,
            "%s (%.20r) is not valid Latin-1. Use %s.encode('utf-8') "
            "if you want to send it encoded in UTF-8." %
            (name.title(), data[err.start:err.end], name)) from None
def _encode ( data , name = 'data' ) : try : return data . encode ( "latin-1" ) except UnicodeEncodeError as err : raise UnicodeEncodeError ( err . encoding , err . object , err . start , err . end , "%s (%.20r) is not valid Latin-1. Use %s.encode('utf-8') " "if you want to send it encoded in UTF-8." % ( name . title ( ) , data [ err . start : err . end ] , name ) ) from None