简体   繁体   中英

python utf-8 encoding error in my computer

I made a mail verification application with python . When I write the application codes in the online python editor and on another computer, it works properly and sends the code, but the visual studio installed on my computer gives an error and the error is like this; Error! 'utf-8' codec can't decode byte 0xfd in position 5: invalid start byte

here is my code

from smtplib import SMTP import random randomCode = random.randint(10000,99999) sendTo = "******@gmail.com" try: # Mail Message Information subject = "E-Mail authentication system" message = ("Here is E-Mail authentication system"+ ":" str(randomCode)) contents = "Subject: {0}\n\n{1}".format(subject,message) # Account Information mailaddress = "**********@gmail.com" password = "password" # To Whom To Send Information mail = SMTP("smtp.gmail.com", 587) mail.ehlo() mail.starttls() mail.login(mailaddress,password) mail.sendmail(mailadress, sendTo, contents.encode("utf-8")) print("Your code has been sent successfully:") codeChecker = int(input("Please enter the code: ")) if codeChecker == randomCode. print("You are succesfuly login:") print("Login screen") else: print("The code you entered is incorrect please try again") except Exception as e. print("Error!\n {0}".format(e))

Try to determine or recognise the encoding of the input string and decode it first in Unicode and then encode it as UTF-8, for example: str.decode("cp1252").encode("utf-8") .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM