0

I want to login me a my Hotmail's account, with the module smtplib in python3. But I have a problem. The account's password has special characters. I have:

#!/usr/bin/python3
import smtplib
server=str(input("server: "))
email=str(input("email: "))
password="p@sswordñ!"
smtp=smtplib.SMTP(server,587)
smtp.ehlo()
smtp.starttls()
smtp.login(email,password)

My error:

UnicodeEncodeError: 'ascii' codec can't encode character '\xf1' in position 1: ordinal not in range(128)

How Can I solve it?

cleanet
  • 71
  • 6
  • Does this answer your question? [Python 3 smtplib send with unicode characters](https://stackoverflow.com/questions/1429147/python-3-smtplib-send-with-unicode-characters) – hrokr Mar 17 '20 at 01:35
  • The passwords don't allow special characters of ASCII extend, only ASCII printables. https://elcodigoascii.com.ar/ – cleanet Mar 18 '20 at 01:47
  • What happens if you change this line (`password="p@sswordñ!"`) to: `password="p@sswordñ!".encode("utf-8")`? – GordonAitchJay Mar 26 '20 at 05:52

1 Answers1

0

This is a known issue in smtplib. But you can do something like getting input as Unicode. Then the same string applies to another variable when it is used in the method.

server1=str(input("server: "))
email1=str(input("email: "))
password1 = input("Enter the Password: ")

def sendmail():
 server = server1
 email= email1
 password=password1
 smtp=smtplib.SMTP(server,587)
 smtp.ehlo()
 smtp.starttls()
 smtp.login(email,password)