Converts a string argument to a byte string.

def utf8(value, encoding=None):
    """Converts a string argument to a byte string.
    """
    if isinstance(value, _UTF8_TYPES):
        return value
    if not isinstance(value, text_type):
        raise TypeError(
            "Expected bytes, unicode, or None; got %r" % type(value)
        )

    if encoding is not None:
        return value.encode(encoding)

    try:
        return value.encode('utf-8')
    except:
        return value.encode('gbk')