2012-03-19 8 views
1

파이썬 3.2을 사용하고 있습니다. 나는 다음 코드를 사용하여 빌드 로그 파일을 썼다 : 나는 위의 파일을 이메일로 보내 에 다음과 같은 사용하고 그 다음TypeError : 예상 문자열 페이로드 : <class 'bytes'>

rsltFile = open('buildLog.txt', 'wb') 
    p = subprocess.Popen('call ant compile', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 
    for line in p.stdout.readlines(): 
     rsltFile.write(line) 
    retval = p.wait() 

첨부 :

def send_mail(send_from, send_to, subject, text, files=[], server="XXX.XXX.com"): 
    assert type(send_to)==list 
    assert type(files)==list 

    msg = MIMEMultipart() 
    msg['From'] = send_from 
    msg['To'] = COMMASPACE.join(send_to) 
    msg['Date'] = formatdate(localtime=True) 
    msg['Subject'] = subject 

    msg.attach(MIMEText(text)) 

    for f in files: 
    part = MIMEBase('application', "octet-stream") 
    part.set_payload(open(f,"rb").read()) 
    part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f)) 
    msg.attach(part) 

    smtp = smtplib.SMTP(server) 
    smtp.sendmail(send_from, send_to, msg.as_string()) 
    smtp.close() 

을하지만 이 있어요 다음과 같은 오류 :

File "C:\workspace\VCT2400_Service\ServiceApplication\autobuild\myMail.py", line 29, in send_mail 
    smtp.sendmail(send_from, send_to, msg.as_string()) 
    File "C:\Python32\lib\email\message.py", line 168, in as_string 
    g.flatten(self, unixfrom=unixfrom) 
    File "C:\Python32\lib\email\generator.py", line 91, in flatten 
    self._write(msg) 
    File "C:\Python32\lib\email\generator.py", line 137, in _write 
    self._dispatch(msg) 
    File "C:\Python32\lib\email\generator.py", line 163, in _dispatch 
    meth(msg) 
    File "C:\Python32\lib\email\generator.py", line 224, in _handle_multipart 
    g.flatten(part, unixfrom=False, linesep=self._NL) 
    File "C:\Python32\lib\email\generator.py", line 91, in flatten 
    self._write(msg) 
    File "C:\Python32\lib\email\generator.py", line 137, in _write 
    self._dispatch(msg) 
    File "C:\Python32\lib\email\generator.py", line 163, in _dispatch 
    meth(msg) 
    File "C:\Python32\lib\email\generator.py", line 192, in _handle_text 
    raise TypeError('string payload expected: %s' % type(payload)) 
TypeError: string payload expected: <class 'bytes'> 
+0

을보고 추천 : http://bugs.python.org/issue4768 –

답변

관련 문제