In 2024, if you are still facing this error, first ensure that you have enabled two-factor authentication. After doing that, you can create an app password using the following link.
https://myaccount.google.com/apppasswords