<small id='6AyL6'></small><noframes id='6AyL6'>

    <tfoot id='6AyL6'></tfoot>
  • <i id='6AyL6'><tr id='6AyL6'><dt id='6AyL6'><q id='6AyL6'><span id='6AyL6'><b id='6AyL6'><form id='6AyL6'><ins id='6AyL6'></ins><ul id='6AyL6'></ul><sub id='6AyL6'></sub></form><legend id='6AyL6'></legend><bdo id='6AyL6'><pre id='6AyL6'><center id='6AyL6'></center></pre></bdo></b><th id='6AyL6'></th></span></q></dt></tr></i><div id='6AyL6'><tfoot id='6AyL6'></tfoot><dl id='6AyL6'><fieldset id='6AyL6'></fieldset></dl></div>

      <legend id='6AyL6'><style id='6AyL6'><dir id='6AyL6'><q id='6AyL6'></q></dir></style></legend>
          <bdo id='6AyL6'></bdo><ul id='6AyL6'></ul>

        Python 新手,GMail SMTP 错误

        New to Python, GMail SMTP error(Python 新手,GMail SMTP 错误)
        <legend id='M24T6'><style id='M24T6'><dir id='M24T6'><q id='M24T6'></q></dir></style></legend>

          <tfoot id='M24T6'></tfoot>
              <i id='M24T6'><tr id='M24T6'><dt id='M24T6'><q id='M24T6'><span id='M24T6'><b id='M24T6'><form id='M24T6'><ins id='M24T6'></ins><ul id='M24T6'></ul><sub id='M24T6'></sub></form><legend id='M24T6'></legend><bdo id='M24T6'><pre id='M24T6'><center id='M24T6'></center></pre></bdo></b><th id='M24T6'></th></span></q></dt></tr></i><div id='M24T6'><tfoot id='M24T6'></tfoot><dl id='M24T6'><fieldset id='M24T6'></fieldset></dl></div>
                <tbody id='M24T6'></tbody>
            1. <small id='M24T6'></small><noframes id='M24T6'>

                  <bdo id='M24T6'></bdo><ul id='M24T6'></ul>
                • 本文介绍了Python 新手,GMail SMTP 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在为自己编写一个简单的 sendmail 函数,但我不断收到此错误:

                  I am writing a simple sendmail function to myself and I keep getting this error:

                  NameError: 名称SMTPException"未定义

                  NameError: name 'SMTPException' is not defined

                  我的代码有什么问题?有什么建议吗?

                  What is wrong with my code? Any suggestions?

                  import smtplib
                  
                  sender = "user@gmail.com"
                  receiver = ["user@gmail.com"]
                  message = "Hello!"
                  
                  try:
                      session = smptlib.SMTP('smtp.gmail.com',587)
                      session.ehlo()
                      session.starttls()
                      session.ehlo()
                      session.login(sender,'password')
                      session.sendmail(sender,receiver,message)
                      session.quit()
                  except SMTPException:
                      print('Error')
                  

                  推荐答案

                  在 Python 中,您需要通过为其模块添加前缀来完全限定名称:

                  In Python, you will need to fully qualify the name by prefixing it with its module:

                  except smtplib.SMTPException:
                  

                  这是真的,除非您专门导入非限定名称(但我不建议您为您的程序这样做,只是显示可能的情况):

                  This is true unless you specifically import the unqualified name (but I wouldn't recommend doing this for your program, just showing what's possible):

                  from smtplib import SMTPException
                  

                  这篇关于Python 新手,GMail SMTP 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Running .jl file from R or Python(从 R 或 Python 运行 .jl 文件)
                  Running Julia .jl file in python(在 python 中运行 Julia .jl 文件)
                  Using PIP in a Azure WebApp(在 Azure WebApp 中使用 PIP)
                  How to run python3.7 based flask web api on azure(如何在 azure 上运行基于 python3.7 的烧瓶 web api)
                  Azure Python Web App Internal Server Error(Azure Python Web 应用程序内部服务器错误)
                  Run python dlib library on azure app service(在 azure app 服务上运行 python dlib 库)
                  • <bdo id='QUtP3'></bdo><ul id='QUtP3'></ul>
                      <tbody id='QUtP3'></tbody>
                      1. <tfoot id='QUtP3'></tfoot>
                        <i id='QUtP3'><tr id='QUtP3'><dt id='QUtP3'><q id='QUtP3'><span id='QUtP3'><b id='QUtP3'><form id='QUtP3'><ins id='QUtP3'></ins><ul id='QUtP3'></ul><sub id='QUtP3'></sub></form><legend id='QUtP3'></legend><bdo id='QUtP3'><pre id='QUtP3'><center id='QUtP3'></center></pre></bdo></b><th id='QUtP3'></th></span></q></dt></tr></i><div id='QUtP3'><tfoot id='QUtP3'></tfoot><dl id='QUtP3'><fieldset id='QUtP3'></fieldset></dl></div>
                        <legend id='QUtP3'><style id='QUtP3'><dir id='QUtP3'><q id='QUtP3'></q></dir></style></legend>
                        • <small id='QUtP3'></small><noframes id='QUtP3'>