-1
    if choose=="Dr.Xyz":
            print()
            dbt=input("What doubt do you have for Dr.Xyz?: ")
            content="Dear Tutor, following is the asked doubt along with the name, email of the 
            student: ",dbt, "\t Name and email is: ",email,"\t  Please provide the solution as soon 
            as possible. Thank you"


            mail=smtplib.SMTP('smtp.gmail.com',587)
            mail.ehlo()
            mail.starttls()
            mail.login('ipprojectsender1@gmail.com','Password1029')
            mail.sendmail('ipprojectsender1@gmail.com','ipprojectreciever@gmail.com',content)
            mail.close()
            print()
            print("Mail sent to teacher! Won't be long until they reply! Thanks for using 
            TeacherFinder!")

#Here is what i'm gettng as the error

Traceback (most recent call last):
  File "C:\Users\91705\Desktop\TeacherFinder.py", line 81, in <module>
    mail.sendmail('ipprojectsender1@gmail.com','ipprojectreciever@gmail.com',content)
  File "C:\Users\91705\AppData\Local\Programs\Python\Python38-32\lib\smtplib.py", line 886, in sendmail
    (code, resp) = self.data(msg)
  File "C:\Users\91705\AppData\Local\Programs\Python\Python38-32\lib\smtplib.py", line 568, in data
    q = _quote_periods(msg)
  File "C:\Users\91705\AppData\Local\Programs\Python\Python38-32\lib\smtplib.py", line 176, in _quote_periods
    return re.sub(br'(?m)^\.', b'..', bindata)
  File "C:\Users\91705\AppData\Local\Programs\Python\Python38-32\lib\re.py", line 210, in sub
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object
hacker315
  • 1,996
  • 2
  • 13
  • 23

1 Answers1

0

Your content variable should bi in the ASCII range, or a byte string. You can do that easily by,

mail.sendmail( ... , content.encode('utf-8'))

Background

The error TypeError: expected string or bytes-like object indicates one of the function call expected a string or bytes-like object. From the traceback, it's clear the problematic line is

mail.sendmail('ipprojectsender1@gmail.com','ipprojectreciever@gmail.com',content)

According to the doc of smtplib (SMTP.sendmail)

msg may be a string containing characters in the ASCII range, or a byte string. A string is encoded to bytes using the ascii codec, and lone \r and \n characters are converted to \r\n characters. A byte string is not modified.

Shiplu Mokaddim
  • 56,364
  • 17
  • 141
  • 187