SMTPSenderRefused(530,要求b'5.7.0身份验证)

时间:2020-04-06 18:43:46

标签: python django

我使用django创建了一个网站,并且在使用heroku部署时重置密码功能(在本地运行良好)时遇到了一些麻烦,当我尝试使用它时,会弹出错误:

SMTPSenderRefused at /password-reset/ (530, b'5.7.0 Authentication Required. Learn more at\n5.7.0 https://support.google.com/mail/?p=WantAuthError a68sm8842573qkd.10 - gsmtp', 'webmaster@localhost') Request Method: POST Request URL: https://mytobiapp.herokuapp.com/password-reset/ Django Version: 3.0.4 Exception Type: SMTPSenderRefused Exception Value:
(530, b'5.7.0 Authentication Required. Learn more at\n5.7.0 https://support.google.com/mail/?p=WantAuthError a68sm8842573qkd.10 - gsmtp', 'webmaster@localhost') Exception Location: /app/.heroku/python/lib/python3.6/smtplib.py in sendmail, line 867 Python Executable: /app/.heroku/python/bin/python Python Version: 3.6.10 Python Path:
['/app/.heroku/python/bin', '/app', '/app/.heroku/python/lib/python36.zip', '/app/.heroku/python/lib/python3.6', '/app/.heroku/python/lib/python3.6/lib-dynload', '/app/.heroku/python/lib/python3.6/site-packages']

settings.py

EMAIL_BACKEND="django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST="smtp.gmail.com"
EMAIL_PORT=587
EMAIL_USE_TLS= True
EMAIL_HOST_USER = os.environ.get("GMAIL")
EMAIL_HOST_PASSWORD = os.environ.get("CONTRASEÑA_GMAIL")

我已经尝试允许访问权限较低的应用访问acces并使用google的displayunlockcaptcha功能,但是似乎没有任何效果。任何帮助将不胜感激

1 个答案:

答案 0 :(得分:1)

您可能没有正确保存环境变量。 要测试您的变量是否正常工作,请在该目录中尝试。

import os
a = os.environ.get('variable_a')
b = os.environ.get('variable_b')
print(a, b)

如果未设置,则应给出None。