开发者

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

开发者 https://www.devze.com 2023-04-05 01:50 出处:网络
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)

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开发者_Go百科 solve this problem?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消