Pydev无法运行在终端中运行良好的.py文件

时间:2015-03-07 02:52:08

标签: python eclipse pydev

我开始在Eclipse中使用Pydev 我的phtyon版本是3.4.3
这是我想要运行的代码

import smtplib

from email.mime.text import MIMEText

import codecs
fp = codecs.open("/Users/Chois/Desktop/textfile", 'rb', 'utf-8') 


msg = MIMEText(fp.read())
fp.close()

me = "abcd@gmail.com"
you = "efgh@naver.com"
msg['Subject'] = "hi.."
msg['From'] = me
msg['To'] = you

s = smtplib.SMTP_SSL('smtp.gmail.com',465)
s.login(me, "password")
s.sendmail(me, you, msg.as_string())
s.quit()

它通过“python test.py”在终端中运行良好 但是,当我试图在Pydev中运行它时,有一些类似下面的错误

Traceback (most recent call last):
  File "/Users/Chois/Downloads/eclipse/plugins/org.python.pydev_3.9.2.201502050007/pysrc/pydevd.py", line 2235, in <module>
    globals = debugger.run(setup['file'], None, None)
  File "/Users/Chois/Downloads/eclipse/plugins/org.python.pydev_3.9.2.201502050007/pysrc/pydevd.py", line 1661, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Users/Chois/Documents/workspace/Test/src/test.py", line 9, in <module>
    msg = MIMEText(fp.read())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/mime/text.py", line 30, in __init__
    self.set_payload(_text, _charset)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/message.py", line 226, in set_payload
    self.set_charset(charset)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/message.py", line 262, in set_charset
    self._payload = self._payload.encode(charset.output_charset)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-4: ordinal not in range(128)

我不知道为什么会发生这种情况 以下是我在Pydev中制作python项目文件时使用的设置

enter image description here

如果你要提出意见或建议,我会非常感激。感谢。

0 个答案:

没有答案