Search code examples
python-3.xexceptiongmail-imap

Variable holding "imaplib.IMAP4_SSL("imap.google.com")" throws overly-vague "Syntax error"


I have searched again and again but nothing seems to be solving my problem. When

mail = imaplib.IMAP4_SSL("imap.google.com")

is declared it throws a syntax error, but tells me absolutely nothing but that it is incorrect. Does anyone know what is going on here or knows how to fix it? Feel free to ask for more details if needed. I am using SMTP port 143.

Code snippet:

from subprocess import Popen
import smtplib
import time
import imaplib
import email
import threading

ORG_EMAIL = "@gmail.com"
FROM_EMAIL = "magikboy01" + ORG_EMAIL
FROM_PWD = "********"
SMTP_SERVER = "imap.gmail.com"
SMTP_PORT = 143

def read_email_from_gmail():
    threading.Timer(300, read_email_from_gmail().start()

    mail = imaplib.IMAP4_SSL(SMTP_SERVER)
    mail.login( FROM_EMAIL, FROM_PWD )
    mail.select( 'inbox' )

Solution

  • You are missing a close parentheses:

    threading.Timer(300, read_email_from_gmail().start()
    

    should be:

    threading.Timer(300, read_email_from_gmail().start())
    

    That is the root of the syntax error, but due to the way compilers work, sometimes they get the error on the next line.