import six


def _post_data(session, url, data, content_type='application/xml'):
    """
    POST data to *url*, properly encoding to bytes and setting Content-Type
    header with charset if needed.
    """
    if isinstance(data, six.text_type):
        data = data.encode('utf-8')
        if 'charset' not in content_type:
            content_type += '; charset=utf-8'
    return session.post(url, data, headers={'content-type': content_type})