0
import yagmail

user = 'myEmail@gmail.com'
password = 'myPassword'

yag = yagmail.SMTP(user, password)

yag.send('myOtherEmail@gmail.com', 'Subject')

the final error(before it there are just a bunch of functions pointing at each other) I get is the following:

hostname, aliases, ipaddrs = gethostbyaddr(name) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe1 in position 9: invalid continuation byte

I've very little experience with python, even less with this library and I cannot find any solutions online that work for me.

I'm using the windows version of PyCharm and both python versions are installed (python2 and python3)

The interpreter doesn't work either

edit: doesn't work with smtplib either. The same problem occurs

3DartBlade
  • 71
  • 7
  • This can be caused by the hosts file on your computer containing non-ASCII characters, while not being encoded as UTF-8. Changing the host file encoding may cause problems, so changing the host file entries to be ASCII is usually the solution. – snakecharmerb Feb 22 '21 at 12:35
  • Could you point me in the right direction on how to do that? Thanks! – 3DartBlade Feb 23 '21 at 10:14
  • I encoded the strings, however now I get an "invalid address" error. I suspect that @ might not be an ASCII character. ` yag = yagmail.SMTP(user.encode("ASCII"), password.encode("ASCII")) yag.send('MyEmail@gmail.com'.encode("ASCII"), 'subject'.encode("ASCII")) ` – 3DartBlade Feb 23 '21 at 10:31
  • @snakecharmerb I tried it with lowercase letters as well if it matters. – 3DartBlade Feb 23 '21 at 10:45
  • The hosts file is a file on your computer that contains hostnames, including that of your own computer. [This site](http://www.whereismyhostsfile.com/) may help you locate it. You need to check this file for non-ASCII characters; the data in your code is not the problem. – snakecharmerb Feb 23 '21 at 17:57
  • @snakecharmerb I renamed my pc and it works perfectly. However I would like to know how could I fix that problem if I couldn't rename the computer, for instance if a client asked for this problem and they do not want to rename their computer which contains non-ascii characters? Thanks! – 3DartBlade Feb 24 '21 at 18:42
  • Assuming that you are using Windows, [this answer](https://serverfault.com/a/452269/485567) seems to suggest that you can change the encoding of the hosts file (to UTF-8, in this case). Whether this is safe or not I don't know. – snakecharmerb Feb 25 '21 at 11:46

0 Answers0