Skip to main content
 首页 » 编程设计

python之使用 Python 导入 smtplib 时遇到问题

2024年11月01日9jillzhang

当我有一个简单的 python 代码时:

import smtplib 

我收到错误:

Traceback (most recent call last): 
  File "C:\Users\David\Desktop\email.py", line 25, in <module> 
    from smtplib import SMTP_SSL as SMTP       # this invokes the secure SMTP pr 
otocol (port 465, uses SSL) 
  File "C:\Python27\lib\smtplib.py", line 1 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtm 
l11/DTD/xhtml11.dtd"> 
    ^ 
SyntaxError: invalid syntax 

我不确定我做错了什么。

请您参考如下方法:

唯一的解释是您的 smtplib.py 以某种方式被替换为 html 文件。尝试在文本编辑器中打开 C:\Python27\lib\smtplib.py 并检查。

我无法告诉你这是怎么发生的,但在这种情况下最好重新安装 python。