Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Strange effects using the email.message.Message class

Reply
Thread Tools

Strange effects using the email.message.Message class

 
 
Rogério Brito
Guest
Posts: n/a
 
      09-09-2009
Dear people,

I am a newbie in Python and I'm just writing a program to rip the HTML parts of
multipart/alternative e-mails that come with a plain text version.

For this task, I decided to leave perl aside for this task and tried to code
something in Python using what is already available in the libraries.

Unfortunately, the program that I coded exhibits a strange problem, even if I
follow what is written on the reference for Python 2.6 (I'm actually running
Debian GNU/Linux on my system, sid, updated daily).

The strange thing is that I even checked page 500 of "Python Cookbook", by Alex
Martelli, et. al. and the code in that page is actually quite similar to what I
wrote.

I'm attaching the program that I've written here, together with a fake e-mail
that triggers the bug.

The messages that I get, BTW, are the following:

# http://www.python.org/doc/2.5.2/lib/...l.message.html
# http://docs.python.org/library/email.message.html
#
# Traceback (most recent call last):
# File "test.py", line 8, in <module>
# print msg.as_string(),
# File "/usr/lib/python2.5/email/message.py", line 131, in as_string
# g.flatten(self, unixfrom=unixfrom)
# File "/usr/lib/python2.5/email/generator.py", line 84, in flatten
# self._write(msg)
# File "/usr/lib/python2.5/email/generator.py", line 109, in _write
# self._dispatch(msg)
# File "/usr/lib/python2.5/email/generator.py", line 135, in _dispatch
# meth(msg)
# File "/usr/lib/python2.5/email/generator.py", line 175, in _handle_text
# raise TypeError('string payload expected: %s' % type(payload))
# TypeError: string payload expected: <type 'list'>

If anybody could help me with the code, I would be very grateful. Also, if you
can criticize what I wrote, I would be very happy, as I would like to improve my
Python-fu (which is minimal, unfortunately).


Thanks in advance, Rogério Brito.

--
Rogério Brito : rbrito@{mackenzie,ime.usp}.br : GPG key 1024D/7C2CAEB8
http://www.ime.usp.br/~rbrito : http://meusite.mackenzie.com.br/rbrito
Projects: algorithms.berlios.de : lame.sf.net : vrms.alioth.debian.org

 
Reply With Quote
 
 
 
 
Sean DiZazzo
Guest
Posts: n/a
 
      09-09-2009
On Sep 8, 6:23*pm, Rogério Brito <(E-Mail Removed)> wrote:
> Dear people,
>
> I am a newbie in Python and I'm just writing a program to rip the HTML parts of
> multipart/alternative e-mails that come with a plain text version.
>
> For this task, I decided to leave perl aside for this task and tried to code
> something in Python using what is already available in the libraries.
>
> Unfortunately, the program that I coded exhibits a strange problem, even if I
> follow what is written on the reference for Python 2.6 (I'm actually running
> Debian GNU/Linux on my system, sid, updated daily).
>
> The strange thing is that I even checked page 500 of "Python Cookbook", by Alex
> Martelli, et. al. and the code in that page is actually quite similar to what I
> wrote.
>
> I'm attaching the program that I've written here, together with a fake e-mail
> that triggers the bug.
>
> The messages that I get, BTW, are the following:
>
> #http://www.python.org/doc/2.5.2/lib/...l.message.html
> #http://docs.python.org/library/email.message.html
> #
> # Traceback (most recent call last):
> # * File "test.py", line 8, in <module>
> # * * print msg.as_string(),
> # * File "/usr/lib/python2.5/email/message.py", line 131, in as_string
> # * * g.flatten(self, unixfrom=unixfrom)
> # * File "/usr/lib/python2.5/email/generator.py", line 84, in flatten
> # * * self._write(msg)
> # * File "/usr/lib/python2.5/email/generator.py", line 109, in _write
> # * * self._dispatch(msg)
> # * File "/usr/lib/python2.5/email/generator.py", line 135, in _dispatch
> # * * meth(msg)
> # * File "/usr/lib/python2.5/email/generator.py", line 175, in _handle_text
> # * * raise TypeError('string payload expected: %s' % type(payload))
> # TypeError: string payload expected: <type 'list'>
>
> If anybody could help me with the code, I would be very grateful. Also, if you
> can criticize what I wrote, I would be very happy, as I would like to improve my
> Python-fu (which is minimal, unfortunately).
>
> Thanks in advance, Rogério Brito.
>
> --
> Rogério Brito : rbrito@{mackenzie,ime.usp}.br : GPG key 1024D/7C2CAEB8http://www.ime.usp.br/~rbrito:http://meusite.mackenzie.com.br/rbrito
> Projects: algorithms.berlios.de : lame.sf.net : vrms.alioth.debian.org
>
> *drop-alternatives.py
> 1KViewDownload
>
> *triggers-the-problem.mbx.gz
> < 1KViewDownload


You need to modify line 28 to read: body = part.get_payload()

~Sean
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange effects from IE7 browser freezing on ASP site =?Utf-8?B?RGFu?= ASP .Net 7 04-30-2006 04:13 AM
Removing session bean twice - strange effects in JBoss Alex Molochnikov Java 0 10-06-2005 01:35 AM
Calling DataBind() multiple times-- strange side effects? Jim Bancroft ASP .Net 2 12-28-2004 12:57 PM
Strange performance effects Roland C++ 3 01-20-2004 02:10 PM



Advertisments