This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: gethostbyname(gethostname()) fails on misconfigured system
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, jakamkon, nnorwitz, tkadlubo
Priority: normal Keywords:

Created on 2005-08-02 12:17 by tkadlubo, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg25951 - (view) Author: Tadeusz Andrzej Kadlubowski (tkadlubo) Date: 2005-08-02 12:17
Hello,

I downloaded python CVS tree, compiled it and ran tests. 

Two tests failed: urllib2 and mimetools. Both in the same fashion, 
when doing socket.gethostbyname(socket.gethostname())

(It is used in mimetools.py library in line 130 and in test_urllib2.py 
test unit in line 352.)

In the interpreter it fails in the following way:

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

The reason is that my hostname is bogus, no single DNS knows 
about it, and I don't see any reason to set up a DNS server on my 
box. Of course editing /etc/hosts and adding my hostname as an 
alias for 127.0.0.1 solves the problem.

Anyway I don't see any particular reason why the library shouldn't 
handle such situation i.e. when there's no connection between 
hostname and IP address.

What do you think about it? I can make a SF patch item to solve 
this issue if you like. I am quite sure adding try/catch will make it 
in both cases.
msg25952 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2005-09-30 06:33
Logged In: YES 
user_id=33168

Please provide a patch and attach it to this report.  Thanks.
msg25953 - (view) Author: Kuba Kończyk (jakamkon) Date: 2006-03-31 16:42
Logged In: YES 
user_id=1491175

Patch #1462230 fix it
msg25954 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-03-31 17:41
Logged In: YES 
user_id=849994

Applied patch in rev. 43490.
History
Date User Action Args
2022-04-11 14:56:12adminsetgithub: 42243
2005-08-02 12:17:12tkadlubocreate