Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Email parsing: TypeError: parse() takes at least 2 arguments (2 given)

Tags:

python

I am getting the following error while calling a built-in function to parse an email in Python.

txt = parser.Parser.parse(fd, headersonly=False)

And the error i got is

TypeError: parse() takes at least 2 arguments (2 given).

Can anybody tell me the way to solve this problem?

like image 657
Shobitha Avatar asked Sep 16 '11 04:09

Shobitha


2 Answers

I got the same basic error for a different reason: specifying an argument that has a default value but forgetting to give an argument that doesn't have any default value. For instance,

def greeting(name,root = "Hello, "):
    print root + name
greeting(root = "Good morning, ")

returns

TypeError: greeting() takes at least 1 argument (1 given)

The "1 given" here is the (optional) "root" argument but the (required) "name" argument was erroneously omitted.

like image 99
RubenGeert Avatar answered Nov 14 '22 09:11

RubenGeert


This is because .parse() is an instance method, not a class method.

Instead, try Parser().parse(…) or possibly email.message_from_file/email.message_from_string.

like image 10
David Wolever Avatar answered Nov 14 '22 08:11

David Wolever