Google Calendar API

Question:
I’m trying to connect to and then update my calendar via the google calendar api. I am failing to get authorization to my account.
Repl link:

    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)
        # Save the credentials for the next run
        with open('token.json', 'w') as token:
            token.write(creds.to_json())

    try:
        service = build('calendar', 'v3', credentials=creds)

I’m having errors with creds = flow.run_local_server(port=0). It gives me link to go through the auth flow but then I get an error 400 redirect_uri_mismatch