[ python-Bugs-913698 ] smtplib : module bug with unresolved hostname

SourceForge.net noreply at sourceforge.net
Sun Mar 14 12:35:54 EST 2004


Bugs item #913698, was opened at 2004-03-10 21:49
Message generated for change (Settings changed) made by chaica
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=913698&group_id=5470

Category: Extension Modules
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Zarro (chaica)
Assigned to: Nobody/Anonymous (nobody)
>Summary: smtplib : module bug with unresolved hostname

Initial Comment:
I checked in the last cvs and the bug wasn't corriged.

if your hostname can't be resolved, so the module will
panic and raise a socket.gaierror in line 254:

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

>>> import socket
>>> socket.gethostname()
'desktop'
>>> socket.gethostbyname(socket.gethostname())
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
socket.gaierror: (-2, &#039;Name or service not known&#039;)

To correct, catch the exception and give a generic
value for self.local_hostname, for example localhost
127.0.0.1

try:
    addr = socket.gethostbyname(socket.gethostname())
    self.local_hostname = &#039;[%s]&#039; % addr
except socket.gaierror, msg:
    self.local_hostname = &#039;[%s]&#039; % &#039;127.0.0.1&#039;

Keep me tuned,
chaica at ohmytux.com


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=913698&group_id=5470



More information about the Python-bugs-list mailing list