import requests


def send_proms_pingback(pingback_target_uri, payload, mimetype='text/turtle'):
    """
    Generates and posts a PROMS pingback message

    :param pingback_target_uri: a URI, to where the pingback is sent
    :param payload: an RDF file, in one of the allowed formats and conformant with the PROMS pingback message spec
    :param mimetype: the mimetype of the RDF file being sent
    :return: True or an error message
    """

    headers = {'Content-Type': mimetype}

    # send the post
    try:
        r = requests.post(pingback_target_uri, data=payload, headers=headers)
        result = (r.status_code == 201)
        if result:
            return [True, r.content]
        else:
            return [False, r.content]
    except Exception as e:
        print(str(e))
        return [False, str(e)]