I am trying to parse gmail emails. From http://yuji.wordpress.com/2011/06/22/python-imaplib-imap-example-with-gmail/ I have the following:
def get_first_text_block(self, email_message_instance):
maintype = email_message_instance.get_content_maintype()
if maintype == 'multipart':
for part in email_message_instance.get_payload():
if part.get_content_maintype() == 'text':
return part.get_payload()
elif maintype == 'text':
return email_message_instance.get_payload()
def hello(request):
....
first = qs[0]
one = first.get_email_object()
print one['To']
out = get_first_text_block(one)
I'm getting:
get_first_text_block() takes exactly 2 arguments (1 given)
What am I doing wrong?
self
is usually used for instance methods, passing a pointer of the instance to the function.
Well, we don't seem to need it here. You can just omit it:
def get_first_text_block(email_message_instance):
maintype = email_message_instance.get_content_maintype()
if maintype == 'multipart':
for part in email_message_instance.get_payload():
if part.get_content_maintype() == 'text':
return part.get_payload()
elif maintype == 'text':
return email_message_instance.get_payload()
I don't know where you get this code from, but i hope this works as expected!
You have to invoke the function through a View instance.
It's a common error in Django users don't instantiate class Views when writting url patterns. If you have the view "MyView" you must provide an instance MyView() to the url pattern.
If you have some class:
class SomeClass:
def some_function(self, foo): pass
you must call it like this:
some_instance = SomeClass()
some_instance.some_function(foo)
if you call it like this:
SomeClass.some_function(foo)
you don't have actually passed a object (self) as first param to some_function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With