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

  • SEARCH
  • Home
  • 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 6941063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:50:14+00:00 2026-05-27T12:50:14+00:00

I got payload as a string instance using get_payload() method. But I want my

  • 0

I got payload as a string instance using get_payload() method. But I want my payload in a way where I could access it word by word
I tried several things like as_string() method, flatten() method, get_charset() method , but every time there is some problem.

I got my payload using the following code

import email
from email import *
f=open('mail.txt','r')
obj=email.parser.Parser()
fp=obj.parse(f)
payload=fp.get_payload()
  • 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-27T12:50:15+00:00Added an answer on May 27, 2026 at 12:50 pm

    Just tested your snippet with a couple of my own raw emails. Works fine…

    get_payload() returns either a list or string, so you need to check that first

    if isinstance(payload, list):
        for m in payload:
            print str(m).split()
    
    else:
        print str(m).split()
    

    Edit

    Per our discussion, your issue was that you were not checking is_multipart() on the fp object, which actually is a message instance. If fp.is_multipart() == True, then get_payload() will return a list of message instances. In your case, based on your example mail message, it was NOT multipart, and fp was actually the object you were interesting in.

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

Sidebar

Related Questions

I want to receive a JSON object using Ruby. I've written this: require 'sinatra'
Got this error when parsing my html page using XPATH.. i am also using
I just got a doubt whether the XMLs we are using for our SOAP/REST-based
I'm writing a firefox-extension and I've got this little json file: for (;;);{__ar:1,payload:{stackable:[true,false],title:{__html:How You
I've got a couple projects that were built using hookbox to manage real-time message
Got a partial answer from searching in this thread: Viewing raw RSS feed? But
Maybe my Google-fu just isn't strong enough. Using GCC 4.4.3, I've got a set
Got a bluescreen in windows while cloning a mercurial repository. After reboot, I now
got a new blog at wordpress few days ago ( http://ghads.wordpress.com ) and I
Got a class that serializes into xml with XMLEncoder nicely with all the variables

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.