Python,Django:catch-SMTPRecipientsRefused。获得;未定义变量";相反

Python,Django:catch-SMTPRecipientsRefused。获得;未定义变量";相反,python,django,exception-handling,smtp,Python,Django,Exception Handling,Smtp,当我尝试发送电子邮件时,出现以下异常: Traceback (most recent call last): my_own_functions ... File "C:\Python27\lib\site-packages\django\core\mail\message.py", line 248, in send return self.get_connection(fail_silently).send_messages([self]) File "C:\Python2

当我尝试发送电子邮件时,出现以下异常:

Traceback (most recent call last):
  my_own_functions ...
  File "C:\Python27\lib\site-packages\django\core\mail\message.py", line 248, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "C:\Python27\lib\site-packages\django\core\mail\backends\smtp.py", line 92, in send_messages
    sent = self._send(message)
  File "C:\Python27\lib\site-packages\django\core\mail\backends\smtp.py", line 110, in _send
    email_message.message().as_string())
  File "C:\Python27\lib\smtplib.py", line 733, in sendmail
    raise SMTPRecipientsRefused(senderrs)
SMTPRecipientsRefused: {'aaa': (553, "5.1.2 We weren't able to find the recipient domain. Please check for any\n5.1.2 spelling errors, and make sure you didn't enter any spaces, periods,\n5.1.2 or other punctuation after the recipient's email address. q10sm6381464wie.2")}
我希望捕获该异常,并已尝试:

try:
    sendActivationEmail()
except SMTPRecipientsRefused:
    return "error"

然而,这给了我一个“未定义变量”的错误。它无法识别SMTPrecipients。在Eclipse中,它说“Undefined variable:SMTPRecipientsRefused”

异常与Python中的任何其他类一样:在引用它之前,需要将它导入到代码中。您需要从smtplib导入SMTPRecipientsRefused

请粘贴准确的错误消息和堆栈跟踪,以便引发并捕获正确的错误。请将代码粘贴到异常处理程序中。将
除了SMTPRecipeintsRefused
更改为
除了smtplib。Recipients Refused
或只是
smtplib。Recipients Refused
很好,谢谢,解决了它。虽然只是smtplib.Recipients融合不起作用(可能是因为我没有导入smtlib),但在导入smtplib后,我能够使用
smtplib.SMTPrecipients融合