Socket - gaierror

Larry Bates larry.bates at websafe.com
Mon Aug 27 21:32:35 CEST 2007


half.italian at gmail.com wrote:
> Hi all,
> 
> I'm having trouble with the socket module resolving a hostname.  It
> seems like this is a system level problem, but I'm not even sure where
> to start.  I can ping the smtp server by name and IP, but when
> smtp.SMTP("theHost") tries to get the hostname, it keeps giving me the
> following error:
> 
>   File "bin/program.py", line 123, in notify
>     smtp = smtplib.SMTP("theHost")
> 
>   File "/usr/lib/python2.4/smtplib.py", line 255, in __init__
>     addr = socket.gethostbyname(socket.gethostname())
> 
> gaierror: (-2, 'Name or service not known')
> 
> I tried changing to a different smtp server, using an ip instead of a
> host name.  I could ping both boxes by name oor IP.
> 
> any ideas?
> 
> ~Sean
> 
The specific error shown is a DNS resolution problem.  Based on the
URL "theHost" smtplib can't resolve to an IP address (which is what
socket.gethostbyname does).  You don't say what happened when you changed to ip, 
but I suspect it is a different error or some other problem.  Maybe a firewall 
issue (port 25 not open?), but I'm just guessing.

-Larry



More information about the Python-list mailing list