Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75963 > unrolled thread
| Started by | luofeiyu <elearn2014@gmail.com> |
|---|---|
| First post | 2014-08-09 18:41 -0700 |
| Last post | 2014-08-09 22:52 -0700 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.python
how to get the subject of email? luofeiyu <elearn2014@gmail.com> - 2014-08-09 18:41 -0700
Re: how to get the subject of email? John Gordon <gordon@panix.com> - 2014-08-10 02:01 +0000
Re: how to get the subject of email? luofeiyu <elearn2014@gmail.com> - 2014-08-09 22:37 -0700
Re: how to get the subject of email? luofeiyu <elearn2014@gmail.com> - 2014-08-09 22:52 -0700
| From | luofeiyu <elearn2014@gmail.com> |
|---|---|
| Date | 2014-08-09 18:41 -0700 |
| Subject | how to get the subject of email? |
| Message-ID | <mailman.12805.1407635303.18130.python-list@python.org> |
I am in python3.4
typ, data = x.con.fetch(b'1', '(RFC822)') #get the first email
text = data[0][1]
message = email.message_from_string(text).get('subject')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\Python34\lib\email\__init__.py", line 40, in message_from_string
return Parser(*args, **kws).parsestr(s)
File "D:\Python34\lib\email\parser.py", line 70, in parsestr
return self.parse(StringIO(text), headersonly=headersonly)
TypeError: initial_value must be str or None, not bytes
message = email.message_from_string(str(text)).get('subject')
message # nothing displayed
[toc] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2014-08-10 02:01 +0000 |
| Message-ID | <ls6jp2$feg$2@reader1.panix.com> |
| In reply to | #75963 |
In <mailman.12805.1407635303.18130.python-list@python.org> luofeiyu <elearn2014@gmail.com> writes:
> message = email.message_from_string(str(text)).get('subject')
> message # nothing displayed
Try using email.message_from_bytes() instead.
Also have a look at
http://stackoverflow.com/questions/19508393/python-email-parsing-issue
for a question very similar to yours. Perhaps something in the code
will help.
--
John Gordon Imagine what it must be like for a real medical doctor to
gordon@panix.com watch 'House', or a real serial killer to watch 'Dexter'.
[toc] | [prev] | [next] | [standalone]
| From | luofeiyu <elearn2014@gmail.com> |
|---|---|
| Date | 2014-08-09 22:37 -0700 |
| Message-ID | <mailman.12807.1407649058.18130.python-list@python.org> |
| In reply to | #75965 |
message = email.message_from_bytes(text)
I get it ,
print(message['Subject']) #can get the subject
But how can i get the body content of message?
no , message['Body'] or message['Content']
On 8/9/2014 7:01 PM, John Gordon wrote:
> In <mailman.12805.1407635303.18130.python-list@python.org> luofeiyu <elearn2014@gmail.com> writes:
>
>> message = email.message_from_string(str(text)).get('subject')
>> message # nothing displayed
> Try using email.message_from_bytes() instead.
>
> Also have a look at
> http://stackoverflow.com/questions/19508393/python-email-parsing-issue
> for a question very similar to yours. Perhaps something in the code
> will help.
>
[toc] | [prev] | [next] | [standalone]
| From | luofeiyu <elearn2014@gmail.com> |
|---|---|
| Date | 2014-08-09 22:52 -0700 |
| Message-ID | <mailman.12808.1407649929.18130.python-list@python.org> |
| In reply to | #75965 |
think you ,i get it .
message = email.message_from_bytes(text)
print(message['Subject']) #can get the subject
But how can i get the body content of message?
message['Body'] or message['Content'] can get none.
On 8/9/2014 7:01 PM, John Gordon wrote:
> In <mailman.12805.1407635303.18130.python-list@python.org> luofeiyu <elearn2014@gmail.com> writes:
>
>> message = email.message_from_string(str(text)).get('subject')
>> message # nothing displayed
> Try using email.message_from_bytes() instead.
>
> Also have a look at
> http://stackoverflow.com/questions/19508393/python-email-parsing-issue
> for a question very similar to yours. Perhaps something in the code
> will help.
>
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web