title: TypeError: string payload expected: <class 'bytes'>
body: <p>I am using <strong>Python 3.2</strong>.
  I <strong>wrote a build log file</strong> by using the following code:</p>
  
  <pre><code>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()
  </code></pre>
  
  <p>Then I am using the following to <strong>send an email with above file attached</strong>:</p>
  
  <pre><code>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()
  </code></pre>
  
  <p>but I <strong>got the following error</strong>:</p>
  
  <pre><code>  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: &lt;class 'bytes'&gt;
  </code></pre>