Error 404 when trying to add any internet account to Mac
I am trying to add my gmail accounts to my mac in order to synchronize my calendars with the native calendar app. Whenever I click on the plus button to add an account, a Safari browser opens asking me for my log in details. I successfully log in. Then it asks me if I am ok with giving the required permissions. When I accept, it gives me a 404 error stating that the request was malformed and it should not be retried. Attached is a screenshot of it.
Things that I've tried are:
1) Setting Safari to be my default browser
2) Clearing the Safari cache
3) Restarting the computer
None have been effective. Could use some help!
For reference, I am using Sonoma 14.3
MacBook Pro 14″, macOS 14.3