• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python SyntaxError: invalid syntax (help)

Linh Lee

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('imap.mail.yahoo.com').login('[email protected]', 'PWD', 'Bulk') as mailbox:
    DELETE messages that contains 'a@*.*' in body from Bulk folder

λ python DeleteEmailFiles.py
  File "C:\Users\Desktop\Desktop\Python Spam Buster\DeleteEmailFiles.py", line 5
    DELETE messages that contains 'a@*.*' in body from Bulk folder
SyntaxError: invalid syntax
Last edited:
My bad, line needed to be commented out!
New error now:
λ python DeleteEmailFiles.py
Traceback (most recent call last):

  File "C:\Users\Desktop\Desktop\Python Spam Buster\DeleteEmailFiles.py", line 6, in <module>
  File "C:\Users\Desktop\AppData\Local\Programs\Python\Python310\lib\site-packages\imap_tools\mailbox.py", line 176, in delete
    uid_str = clean_uids(uid_list)
  File "C:\Users\Desktop\AppData\Local\Programs\Python\Python310\lib\site-packages\imap_tools\utils.py", 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
Top Bottom