我试图运行这段产生错误的代码:
#!/usr/bin/python
import smtplib
msg = 'Hello world.'
server = smtplib.SMTP('smtp.gmail.com',587) #port 465 or 587
server.ehlo()
server.starttls()
server.ehlo()
server.login('me@gmail.com','pass')
server.sendmail('me@gmail.com','someoneelse@gmail.com',msg)
server.close()
这是错误:
Traceback (most recent call last):
File "sendmail2.py", line 2, in <module>
import smtplib
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 163, in <module>
import ssl
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 58, in <module>
import textwrap
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/textwrap.py", line 32, in <module>
class TextWrapper:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/textwrap.py", line 74, in TextWrapper
whitespace_trans = string.maketrans(_whitespace, ' ' * len(_whitespace))
AttributeError: 'module' object has no attribute 'maketrans
我想知道问题是什么?在我看来,如果smtplib被破坏了,为什么呢?