SESを使用しているDjangoアプリで発生する500エラーを解消したい
書籍名:動かして学ぶ Python Django開発入門
を参考に学習を進めているのですが、本番環境にて
・ログイン
・サインアップ(ユーザー登録)
・パスワードリセット
・お問合せフォーム送信
の際に500エラーが発生している状態です。
変更を反映する設定が必要 or 修正箇所が誤っている
もしくは別の問題なのでしょうか。
ご確認いただければ幸いです。
発生している問題・エラーメッセージ
[ERROR] /home/app_admin/venv_private_diary/lib64/python3.7/site-packages/django/utils/log.py(Line:230) Internal Server Error: /accounts/login/ Traceback (most recent call last): File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner response = get_response(request) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/django/core/handlers/base.py", line 179, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/django/views/generic/base.py", line 70, in view return self.dispatch(request, *args, **kwargs) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/django/utils/decorators.py", line 43, in _wrapper return bound_method(*args, **kwargs) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/django/views/decorators/debug.py", line 89, in sensitive_post_parameters_wrapper return view(request, *args, **kwargs) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/allauth/account/views.py", line 146, in dispatch return super(LoginView, self).dispatch(request, *args, **kwargs) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/allauth/account/views.py", line 75, in dispatch request, *args, **kwargs File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/django/views/generic/base.py", line 98, in dispatch return handler(request, *args, **kwargs) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/allauth/account/views.py", line 102, in post response = self.form_valid(form) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/allauth/account/views.py", line 159, in form_valid return form.login(self.request, redirect_url=success_url) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/allauth/account/forms.py", line 200, in login email=email, File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/allauth/account/utils.py", line 175, in perform_login send_email_confirmation(request, user, signup=signup, email=email) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/allauth/account/utils.py", line 346, in send_email_confirmation email_address.send_confirmation(request, signup=signup) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/allauth/account/models.py", line 62, in send_confirmation confirmation.send(request, signup=signup) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/allauth/account/models.py", line 169, in send get_adapter(request).send_confirmation_mail(request, self, signup) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/allauth/account/adapter.py", line 464, in send_confirmation_mail self.send_mail(email_template, emailconfirmation.email_address.email, ctx) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/allauth/account/adapter.py", line 136, in send_mail msg.send() File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/django/core/mail/message.py", line 284, in send return self.get_connection(fail_silently).send_messages([self]) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/django_ses/__init__.py", line 190, in send_messages dkim_headers=self.dkim_headers)} File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/botocore/client.py", line 357, in _api_call return self._make_api_call(operation_name, kwargs) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/botocore/client.py", line 676, in _make_api_call raise error_class(parsed_response, operation_name) botocore.errorfactory.MessageRejected: An error occurred (MessageRejected) when calling the SendRawEmail operation: Email address is not verified. The following identities failed the check in region US-EAST-1: admin@example.com
該当のソースコード
◆forms.py
from django import forms from django.core.mail import EmailMessage from .models import Diary class InquiryForm(forms.Form): name = forms.CharField(label='お名前', max_length=30) email = forms.EmailField(label='メールアドレス') title = forms.CharField(label='タイトル', max_length=30) message = forms.CharField(label='メッセージ', widget=forms.Textarea) def __init__(self,*args,**kwargs): super().__init__(*args,**kwargs) self.fields['name'].widget.attrs['class']= 'form-control col-9' self.fields['name'].widget.attrs['placeholder']= 'お名前をここに入力してください。' self.fields['email'].widget.attrs['class']= 'form-control col-11' self.fields['email'].widget.attrs['placeholder']= 'メールアドレスをここに入力してください。' self.fields['title'].widget.attrs['class']= 'form-control col-11' self.fields['title'].widget.attrs['placeholder']= 'タイトルをここに入力してください。' self.fields['message'].widget.attrs['class']= 'form-control col-11' self.fields['message'].widget.attrs['placeholder']= 'メッセージをここに入力してください。' def send_email(self): name = self.cleaned_data['name'] email = self.cleaned_data['email'] title = self.cleaned_data['title'] message = self.cleaned_data['message'] subject = f'お問合せ{title}' message = f'送信者:{name}\nメールアドレス:{email}\nメッセージ:\n{message}' from_email = '○○@example.com' to_list = [ 'test@example.com' ] cc_list = [ email ] message = EmailMessage(subject=subject, body=message, from_email=from_email, to=to_list, cc=cc_list) message.send() class DiaryCreateForm(forms.ModelForm): class Meta: model = Diary fields = ('title', 'content', 'photo1', 'photo2', 'photo3',) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) for field in self.fields.values(): field.widget.attrs['class']= 'form-control'
試したこと
An error occurred (MessageRejected) when calling the SendRawEmail operation: Email address is not verified. The following identities failed the check in region US-EAST-1: admin@example.com
上記エラーメッセージを参考に、forms.pyに記載されている当該アドレス(admin@example.com)を
AmazonSES において Verification Status:verified になっているアドレス(仮:○○@example.com)へ変更致しました。
ですが、問題は解決されずに同じエラーメッセ―ジが返されます。
補足情報(FW/ツールのバージョンなど)
OS:Amazon Linux2
言語:Python
フレームワーク:Django
webサーバー:Nginx
APサーバー:Gunicorn
データベース:PostgreSQL
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。