gaierror: [Errno 11003] getaddrinfo failed

0 votes

I am trying to send one email using smtp server, but I am getting this below error.

gaierror                                  Traceback (most recent call last)
<ipython-input-17-f14b0f617ec8> in <module>
     14 
     15 try:
---> 16    smtpObj = smtplib.SMTP('nadim70.na@gmail.com',25)
     17    smtpObj.sendmail(sender, receivers, message)
     18    print ("Successfully sent email")
~\anaconda3\lib\smtplib.py in __init__(self, host, port, local_hostname, timeout, source_address)
    249 
    250         if host:
--> 251             (code, msg) = self.connect(host, port)
    252             if code != 220:
    253                 self.close()
~\anaconda3\lib\smtplib.py in connect(self, host, port, source_address)
    334         if self.debuglevel > 0:
    335             self._print_debug('connect:', (host, port))
--> 336         self.sock = self._get_socket(host, port, self.timeout)
    337         self.file = None
    338         (code, msg) = self.getreply()
~\anaconda3\lib\smtplib.py in _get_socket(self, host, port, timeout)
    305             self._print_debug('connect: to', (host, port), self.source_address)
    306         return socket.create_connection((host, port), timeout,
--> 307                                         self.source_address)
    308 
    309     def connect(self, host='localhost', port=0, source_address=None):
~\anaconda3\lib\socket.py in create_connection(address, timeout, source_address)
    705     host, port = address
    706     err = None
--> 707     for res in getaddrinfo(host, port, 0, SOCK_STREAM):
    708         af, socktype, proto, canonname, sa = res
    709         sock = None
~\anaconda3\lib\socket.py in getaddrinfo(host, port, family, type, proto, flags)
    750     # and socket type values to enum constants.
    751     addrlist = []
--> 752     for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    753         af, socktype, proto, canonname, sa = res
    754         addrlist.append((_intenum_converter(af, AddressFamily),
gaierror: [Errno 11003] getaddrinfo failed
Apr 15 in Python by akhtar
• 24,570 points
2,014 views

1 answer to this question.

0 votes

Hi@akhtar,

It most likely means the hostname of your system can't be resolved. Use this below code, it will work.

import socket
socket.getaddrinfo('localhost', 25)
answered Apr 15 by MD
• 55,020 points

Related Questions In Python

0 votes
11 answers
0 votes
1 answer

Python pygame error : Failed loading libpng.dylib: dlopen(libpng.dylib, 2): image not found

Try installing libpng You can do it with ...READ MORE

answered May 31, 2019 in Python by SDeb
• 13,250 points
498 views
0 votes
1 answer

Error:setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

Hello @kartik, Try installing these packages. sudo apt-get install ...READ MORE

answered Jun 5 in Python by Niroj
• 57,260 points
1,338 views
0 votes
1 answer

ImportError: DLL load failed: The specified module could not be found.

Hi@akhtar, You may get this error if you ...READ MORE

answered Jun 22 in Python by MD
• 55,020 points
1,171 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,349 views
0 votes
0 answers
+4 votes
6 answers
0 votes
1 answer

failed: unable to get local issuer certif icate (_ssl.c:1056)'))'

Hi@akhtar, To avoid this error, you need to ...READ MORE

answered Apr 22 in Python by MD
• 55,020 points
404 views
0 votes
1 answer

Command "python setup.py egg_info" failed with error code 1 in C:\Users\Nadeem\AppData\Local\Temp\

Hi@akhtar, I think you are using previous version ...READ MORE

answered May 4 in Python by MD
• 55,020 points
9,031 views