SyntaxError: invalid syntax (help)

Trying to search/delete for specific user with one letter name, “a”, and always changing domains.
Some addresses from this spam:

Need help please, fixing invalid syntax error.


from imap_tools import MailBox, A
with MailBox('').login('', 'PWD', 'Bulk') as mailbox:
    DELETE messages that contains 'a@*.*' in body from Bulk folder


λ python
  File "C:\Users\Desktop\Desktop\Python Spam Buster\", line 5
    DELETE messages that contains 'a@*.*' in body from Bulk folder
SyntaxError: invalid syntax

My guess is that line is supposed to be a comment.
Comment it out and try again to run the code


Correct, sorry didn’t notice that.

New error:

λ python
Traceback (most recent call last):
  File "C:\Users\Desktop\Desktop\Python Spam Buster\", line 6, in <module>
  File "C:\Users\Desktop\AppData\Local\Programs\Python\Python310\lib\site-packages\imap_tools\", line 176, in delete
    uid_str = clean_uids(uid_list)
  File "C:\Users\Desktop\AppData\Local\Programs\Python\Python310\lib\site-packages\imap_tools\", line 30, in clean_uids
    raise TypeError('uid "{}" is not string'.format(str(uid)))
TypeError: uid "<imap_tools.message.MailMessage object at 0x000001A96BC7BD90>" is not string

either the fetch or the delete is expecting a string, and got a fully formed object fed into it instead.

1 Like

@m_hutley thank you for responding, but since I’m a newbie to Python, I have no idea how to use your advice to fix code.

From :

# DELETE all messages from current dir to folder1, *in bulk
mailbox.delete([msg.uid for msg in mailbox.fetch()])

Try changing your mailbox.delete statement like this example (using your fetch)

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.