smtplib.SMTPAuthenticationError: (534, b'5.7.9 Application-specific password required

Viewed 6537

smtplib.SMTPAuthenticationError: (534, b'5.7.9 Application-specific password required. Learn more at\n5.7.9 https://support.google.com/mail/?p=InvalidSecondFactor h22sm15927247pfv.25 - gsmtp')

Environment variable are set but does not work (even though it's the exact value).

  • I have set the app password in google account, captcha is disabled
  • I have set the env variables in .bashrc file export EMAIL_USER='da24@gmail.com'
  • Comparison btw the os.environ.get('EMAIL_USER') and the mail value string is True

I am trying to import this in config file, when I use harcoded values it worked fine, but use I use os.environ.get('EMAIL_USER'), it stops working and throws this error.

3 Answers

Use apps password such as EMAIL_USER="example.com" EMAIL_PASSWORD="twtsxiraaxpcuhuyp". If you do not have a gmail apps password, create a new app with using generate password. Check your apps and passwords https://myaccount.google.com/apppasswords. Good Luck.

Created an App password in google account. Passed the created password into the environment variables and it worked. Just replace the regular password with the app 16 digit app password.

Fortunately found the answer later, a reboot of Linux or the bashrc file reload is required . Unless that happens the env won't register that . Also using python console to set env variables does not work, even after reboot.

Related