Skip to content
Advertisement

SyntaxError on input() supposedly in Python 3

I have a script for sending emails using SMTP_SSL. The code is working fine in PyCharm but in the terminal I get an error.

This is the code:

import  smtplib
s = smtplib.SMTP_SSL("smtp.googlemail.com:465")
mml=input("enter your email address :n")
str(mml)
passr=input("enter your pass:n")
str(passr)
s.login(mml,passr)
em = input("please type the email you want to send :n")
str(em)
a = input("please type the message:n")

    str(a)
    s.sendmail(mml,em,a)

print("nEmail Was Sent..:)")

When I run this in my terminal its giving this after i enter the email:

enter your email address :
mahmoud.wizzo@gmail.com
Traceback (most recent call last):
File "medo.py", line 3, in <module>
mml=input("enter your email address :n")
File "<string>", line 1
mahmoud.wizzo@gmail.com
             ^
SyntaxError: invalid syntax

When I am trying to put the email between quotes, e.g. “mahmoud.wizzo@gmail.com” its working fine.

How can I run my script in the terminal?

Advertisement

Answer

I suspect you’re running your script using Python 2 on the command line. The behaviour of input() changed in Python 3.

Try running python3 my_file.py instead of python my_file.py.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement