New to Python, GMail SMTP error

前端 未结 2 1741
逝去的感伤
逝去的感伤 2021-02-07 08:28

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

NameError: name \'SMTPException\' is not defined

What is wrong with my code? Any

2条回答
  •  误落风尘
    2021-02-07 08:57

    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
    

提交回复
热议问题