def METHOD_NAME(
    key,
    public_id,
    private_id,
    serial=None,
    user_agent="python-yubikey-manager/" + __version__,
):
    modhex_public_id = modhex_encode(public_id)
    data = {
        "aes_key": key.hex(),
        "serial": serial or 0,
        "public_id": modhex_public_id,
        "private_id": private_id.hex(),
    }
    httpconn = HTTPSConnection(_UPLOAD_HOST, timeout=1)  # nosec
    try:
        httpconn.request(
            "POST",
            _UPLOAD_PATH,
            body=json.dumps(data, indent=False, sort_keys=True).encode("utf-8"),
            headers={"Content-Type": "application/json", "User-Agent": user_agent},
        )
    except Exception:
        logger.error("Failed to connect to %s", _UPLOAD_HOST, exc_info=True)
        raise _PrepareUploadFailed(None, None, [_PrepareUploadError.CONNECTION_FAILED])
    resp = httpconn.getresponse()
    if resp.status == 200:
        url = json.loads(resp.read().decode("utf-8"))["finish_url"]
        return url
    else:
        resp_body = resp.read()
        logger.debug("Upload failed with status %d: %s", resp.status, resp_body)
        if resp.status == 404:
            raise _PrepareUploadFailed(
                resp.status, resp_body, [_PrepareUploadError.NOT_FOUND]
            )
        elif resp.status == 503:
            raise _PrepareUploadFailed(
                resp.status, resp_body, [_PrepareUploadError.SERVICE_UNAVAILABLE]
            )
        else:
            try:
                errors = json.loads(resp_body.decode("utf-8")).get("errors")
            except Exception:
                errors = []
            raise _PrepareUploadFailed(resp.status, resp_body, errors)