Local Calendar in Python

trying to create a local calendar with python yes AI help a bit

def create_local_calendar(name, ha_url, token):
    url = f"{ha_url}/api/local_calendar"
    headers = {
        "Authorization": f"Bearer {token}",
        "Content-Type": "application/json"
    }
    payload = {
        "name": name,
        "type": "local"
    }

    r = requests.post(url, headers=headers, json=payload)
    if r.status_code in (200, 201):
        print(f"Created calendar: {name}")
    else:
        print(f"Failed to create calendar: {r.status_code} {r.text}")

    
def check_calendar_features(entity_id, ha_url, token):
    url = f"{ha_url}/api/states/{entity_id}"
    headers = {"Authorization": f"Bearer {token}"}

    r = requests.get(url, headers=headers)
    if r.status_code != 200:
        print("Calendar not found")
        return None

    data = r.json()
    features = data["attributes"].get("supported_features", None)
    print(f"{entity_id} supported_features = {features}")
    return features

def ensure_writable_calendar():
    
    calendar_name = "Roster Write"
    entity_id = "calendar.roster_write"

    print("🔍 Checking if writable calendar exists...")

    # Try checking features first
    features = check_calendar_features(entity_id, HA_URL, HA_TOKEN)

    if features in (3, 5):
        print("✅ Writable calendar already exists.")
        return entity_id

    print("⚠️ Calendar not writable or missing. Creating new one...")

    # Create the calendar
    create_local_calendar(calendar_name, HA_URL, HA_TOKEN)

    # Re-check
    features = check_calendar_features(entity_id, HA_URL, HA_TOKEN)

    if features in (3, 5):
        print("🎉 Writable calendar created successfully!")
        return entity_id

    print("❌ Still not writable — HA created an ICS calendar again.")
    return None

but im getting these errors

HA Sync: Fetching roster and pushing to HA...
🔍 Checking if writable calendar exists...
Calendar not found
⚠️ Calendar not writable or missing. Creating new one...
Failed to create calendar: 404 404: Not Found
Calendar not found
❌ Still not writable — HA created an ICS calendar again.
Ensured writable calendar: None
❌ Cannot continue — no writable calendar available.

what am i missing and what manual should i be reading next