gmail icon indicating copy to clipboard operation
gmail copied to clipboard

AttributeError: 'int' object has no attribute 'add_label' when trying to add label

Open secure-byte opened this issue 8 years ago • 3 comments

Problem occurs when I get multiple emails and then loop through them and try to add the a label to each email.

example:

mails = g.inbox().mail(sender=sender, prefetch=True)
for m in mails:
   m.add_label("Label")

This returns: AttributeError: 'int' object has no attribute 'add_label'

secure-byte avatar Apr 07 '16 17:04 secure-byte

Did you login before? Can you paste more complete code? What is happening there is that "m" is an integer instead of a Message object. Integers don't have add_label method. Make sure you are logged in before doing anything else.

mhyst avatar Apr 07 '16 20:04 mhyst

try adding m.fetch() in the loop before add_label is called. Perhaps just the prefetch has failed.

mhyst avatar Apr 08 '16 02:04 mhyst

I have logged in before the loop of course. The problem occurs when I do some other things in for loop before I add the label to the emails. For example I'm pulling some data from the headers and some text search in the body of the email. When that is done I want to add the label and remove it from inbox but got the before mentioned error.

I resolved it in ugly way by adding a new loop under the first one with only add_label in it. I know, ugly but it's the only thing that worked.

I will try with m.fetch method and see if it will work.

Thanks!

secure-byte avatar Apr 08 '16 07:04 secure-byte