import requests


def update_kodi(host, port, user, password):
    """Sends request to the Kodi api to start a library refresh.
    """
    url = "http://{0}:{1}/jsonrpc/".format(host, port)

    """Content-Type: application/json is mandatory
    according to the kodi jsonrpc documentation"""

    headers = {'Content-Type': 'application/json'}

    # Create the payload. Id seems to be mandatory.
    payload = {'jsonrpc': '2.0', 'method': 'AudioLibrary.Scan', 'id': 1}
    r = requests.post(
        url,
        auth=(user, password),
        json=payload,
        headers=headers)

    return r