def _to_bytes(value, encoding='ascii'):
    result = (value.encode(encoding)
              if isinstance(value, six.text_type) else value)
    if isinstance(result, six.binary_type):
        return result
    else:
        raise ValueError('%r could not be converted to bytes' % (value,))
Converts a string value to bytes, if necessary.
dataset/ETHPy150Open google/oauth2client/oauth2client/_helpers.py/_to_bytes