Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7668757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:26:21+00:00 2026-05-31T15:26:21+00:00

I am using Python 3.2 . I wrote a build log file by using

  • 0

I am using Python 3.2.
I wrote a build log file by using the following 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()

Then I am using the following to send an email with above file attached:

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()

but I got the following error:

  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'>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:26:22+00:00Added an answer on May 31, 2026 at 3:26 pm

    file.read (when opened in ‘rb’ mode) in Python 3 return bytes, you need to either open the file in ‘rt’ mode or use decode the bytes to a string.

    I highly recommend watching http://pyvideo.org/video/948/pragmatic-unicode-or-how-do-i-stop-the-pain

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to access some C code via Python using ctypes, so I wrote
I have a Python script I recently wrote that I call using the command
I am using ImageMagick library with Python ctypes . I wrote a following simple
I wrote an application server (using python & twisted) and I want to start
I recently wrote a parser in Python using Ply (it's a python reimplementation of
I am using python 3.2 currently and I wanted to do write a code
How to Write/Read a file to/from a network folder/share using python? The application will
I switched from NAnt to using Python to write build automation scripts. I am
I've wrote GTK application with python. All graphical user interface is in glade file,
Example from Using YAML with Python Original YAML file contains this # tree format

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.