Another possibilty is, if you are using SSO, you have not specified the profile of the account your are trying to authenticate against.
Just add --profile <<yourprofile>> to the aws ecr get-login-password command to resolve the issue