Newbie question: what is causing my socket error?

google account mynews44 at yahoo.com
Tue Jun 15 05:22:34 CEST 2004


Hiya!  any guidance would be greatly appreciated.

I wrote a little mailer script to be used by otehr tasks to email logs
to specific mail accounts.   I first wrote it for use on a RH8 server
and this works great.   I recently had cause to use it on a new Fedora
Core2 box,  and I get the following error when I run it:

Traceback (most recent call last):
  File "./mailer", line 12, in ?
    mail_server = smtplib.SMTP('melmail')
  File "/usr/lib/python2.3/smtplib.py", line 254, in __init__
    addr = socket.gethostbyname(socket.gethostname())
socket.gaierror: (-2, 'Name or service not known')


Looking at it,  this seems to me to be indicating that DNS is failing,
 so I rewrote it with an IP address of the mail server instead.  Now I
get the same error but with the IP Address listed instead:


Traceback (most recent call last):
  File "./old.mailer", line 10, in ?
    mail_server = smtplib.SMTP('172.30.30.240')
  File "/usr/lib/python2.3/smtplib.py", line 254, in __init__
    addr = socket.gethostbyname(socket.gethostname())
socket.gaierror: (-2, 'Name or service not known')


The script is simple to the nth degree of newbieness, I'd say.  



#!/usr/bin/python

from email.MIMEText import MIMEText
import smtplib
import sys

email = MIMEText(sys.argv[1])
email['Subject'] = "Log Files R Us"

mail_server = smtplib.SMTP('172.30.30.240')
mail_server.sendmail('txt2mail',
                     sys.argv[2:],
                     email.as_string() )
mail_server.quit()




The code in the library at line 254 is 

     addr = socket.gethostbyname(socket.gethostname())

which would kinda support my theory about name resolution,  but not
help me resolve the error.

thanks!!!



More information about the Python-list mailing list