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.
精彩评论