4

I was having issues with the Pi so I put a new image of Jessie on it. I reloaded a python script that has been running for a year and a half that sends a email. Now when it tries to send the email I get these errors. Does anyone know what might have changed that is causing this?

Errors:

  File "GarageDoor3.py", line 111, in <module>
sendEmail(name)
  File "GarageDoor3.py", line 35, in sendEmail
mail=smtplib.SMTP('smtp.gmail.com',587)
  File "/usr/lib/python3.4/smtplib.py", line 242, in __init__
(code, msg) = self.connect(host, port)
  File "/usr/lib/python3.4/smtplib.py", line 321, in connect
self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python3.4/smtplib.py", line 292, in _get_socket
self.source_address)
  File "/usr/lib/python3.4/socket.py", line 491, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.4/socket.py", line 530, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

My code is:

def sendEmail(subject):
        content=(subject + ' is opened')
        mail=smtplib.SMTP('smtp.gmail.com',587)
        mail.ehlo()
        mail.starttls()
        mail.login('xxxx','notrealpassword')
        mail.sendmail('xxx@gmail.com','xxx@gmail.com',content)
  • 1
    I determined the problem to be in my dhcpcd.conf file. It was where I had set the static domain name servers, instead of domain_name_servers I had domain_name_server. Problem solved. – Mobalized Nov 16 '16 at 12:11
  • I made my comment into an answer to make it more obvious the issue is solved. – Dmitry Grigoryev Nov 16 '16 at 13:00
1

The error "Name or service not known" comes from Linux NSS. This is easy to confirm: other programs using NSS (e.g. ping smtp.gmail.com) should fail with a similar error.

Non-local network host names usually come from DNS servers, which are configured either statically, or via DHCP. Fixing DNS configuration and making sure your DNS server is working is therefore the first step to fix the issue.

-1

I had the same error, and realized that my DNS (from my DHCP) was not working, set it to 8.8.8.8 for the Google one. Now works again!

  • 1
    I didn't downvote, but I guess one reason for your downvote is that you must be confusing DHCP with DNS. The 8.8.8.8 IP is a Google DNS server - Nothing to do with DHCP. – Brick Aug 14 '17 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.