Django, send_mail, gets not enough values to unpack, also tried EmailMultiAlternatives, EmailMessage added traceback. the following information hopefully will help you in your endeavors to find solutions.
ValueError at /accounts/password_reset/
not enough values to unpack (expected 2, got 1)
Request Method: POST
Request URL: http://127.0.0.1:8000/accounts/password_reset/
Django Version: 3.1
Exception Type: ValueError
Exception Value:
not enough values to unpack (expected 2, got 1)
Exception Location: d:\Python\Code\dictionary\.env\lib\site-packages\django\core\mail\message.py, line 96, in sanitize_address
Python Executable: d:\Python\Code\dictionary\.env\Scripts\python.exe
Python Version: 3.9.1
class CustomResetPasswordView(PasswordResetView): def post(self, request, *args, **kwargs): email = request.POST.get('email') try: _user = User.objects.filter(email=email).first() if not _user: raise Exception('Invalid email address!') else: context = { 'email' : _user.email, 'domain' : get_current_site(request).domain, 'uid' : urlsafe_base64_encode(force_bytes(_user.pk)), 'user' : _user, 'token' : default_token_generator.make_token(_user), 'protocol': 'https' if request.is_secure() else 'http', }
_superuser = User.objects.filter(is_superuser=True).values_list('email').first()
send_mail(
subject='Password Reset Request',
message=context,
from_email=_superuser,
recipient_list=[_user.email]
)
except Exception as e:
raise
settings:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'mail.smtp2go.com'
EMAIL_HOST_USER = 'confidential'
EMAIL_HOST_PASSWORD = 'confidential'
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/accounts/password_reset/
Django Version: 3.1
Python Version: 3.9.6
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_python3_ldap',
'DictionaryApp.apps.DictionaryappConfig',
'accounts.apps.AccountsConfig',
'crispy_forms']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback (most recent call last):
File "D:\Python\Code\dictionary\.env\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "D:\Python\Code\dictionary\.env\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "D:\Python\Code\dictionary\.env\lib\site-packages\django\views\generic\base.py", line 73, in view
return self.dispatch(request, *args, **kwargs)
File "D:\Python\Code\dictionary\.env\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "D:\Python\Code\dictionary\.env\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "D:\Python\Code\dictionary\.env\lib\site-packages\django\contrib\auth\views.py", line 222, in dispatch
return super().dispatch(*args, **kwargs)
File "D:\Python\Code\dictionary\.env\lib\site-packages\django\views\generic\base.py", line 101, in dispatch
return handler(request, *args, **kwargs)
File "D:\Python\Code\dictionary\DictionaryApp\views.py", line 79, in post
msg.send()
File "D:\Python\Code\dictionary\.env\lib\site-packages\django\core\mail\message.py", line 284, in send
return self.get_connection(fail_silently).send_messages([self])
File "D:\Python\Code\dictionary\.env\lib\site-packages\django\core\mail\backends\smtp.py", line 109, in send_messages
sent = self._send(message)
File "D:\Python\Code\dictionary\.env\lib\site-packages\django\core\mail\backends\smtp.py", line 121, in _send
from_email = sanitize_address(email_message.from_email, encoding)
File "D:\Python\Code\dictionary\.env\lib\site-packages\django\core\mail\message.py", line 96, in sanitize_address
nm, address = addr
Exception Type: ValueError at /accounts/password_reset/
Exception Value: not enough values to unpack (expected 2, got 1)