Django 1.11 EmailMultiAlternatives:ValueError:解包

时间:2017-10-10 10:36:06

标签: django python-3.x email

Iam尝试使用EmailMultiAlternative发送电子邮件。使用Django 1.11,Python 3.4。但是我得到了ValueError。我使用的是SMTP后端。这是代码:

subject = "Hi {} !".format(user.username)
sender = settings.DEFAULT_FROM_EMAIL
recipients = [user.email, ]
html_content = render_to_string('email/hello.html', {'url': url, 'first_name': user.first_name, 'last_name': user.last_name, 'static': HOST + settings.STATIC_URL,})
text_content = strip_tags(html_content)
msg = EmailMultiAlternatives(subject, text_content, sender, recipients)
msg.attach_alternative(html_content, "text/html")
msg.send().

但是我收到以下错误:

  

ValueError:解包需要多于1个值

完成追溯:

  

追踪(最近一次通话):    文件" /home/george/virtuals/new_project/lib/python3.4/site-packages/django/core/handlers/exception.py" ;,第41行,内在      response = get_response(request)    文件" /home/george/virtuals/new_project/lib/python3.4/site-packages/django/core/handlers/base.py" ;,第187行,在_get_response中      response = self.process_exception_by_middleware(e,request)    文件" /home/george/virtuals/new_project/lib/python3.4/site-packages/django/core/handlers/base.py" ;,第185行,在_get_response中      response = wrapped_callback(request,* callback_args,** callback_kwargs)    文件" /home/george/virtuals/new_project/lib/python3.4/site-packages/django/views/generic/base.py" ;,第68行,在视图中      return self.dispatch(request,* args,** kwargs)    文件" /home/george/virtuals/new_project/lib/python3.4/site-packages/django/views/generic/base.py" ;,第88行,在发送中      返回处理程序(request,* args,** kwargs)    文件" /home/george/virtuals/new_project/lib/python3.4/site-packages/django/views/generic/edit.py" ;,第183行,在帖子中      return self.form_valid(form)    文件" /home/george/george/project/new_beco/applications/accounts/views.py",第87行,form_valid      msg.send()    文件" /home/george/virtuals/new_project/lib/python3.4/site-packages/django/core/mail/message.py",第348行,发送      return self.get_connection(fail_silently).send_messages([self])    文件" /home/george/virtuals/new_project/lib/python3.4/site-packages/django/core/mail/backends/smtp.py" ;,第111行,在send_messages中      sent = self._send(message)    文件" /home/george/virtuals/new_project/lib/python3.4/site-packages/django/core/mail/backends/smtp.py" ;,第123行,在_send      from_email = sanitize_address(email_message.from_email,encoding)    文件" /home/george/virtuals/new_project/lib/python3.4/site-packages/django/core/mail/message.py",第136行,在sanitize_address中      nm,addr = addr   ValueError:解包需要多于1个值

0 个答案:

没有答案