httplib does not use "hosts" file (Windows)

Steve Holden sholden at holdenweb.com
Tue Sep 12 16:40:53 EDT 2000


Gilles Lenfant wrote:
> 
> Hi,
> 
> Is it a bug or a feature of httplib
> 
Well, whatever it is, it's to do with sockets and not httplib.
The HTTP __init__ routine just passes whatever it's got down
to the Python sockets library, which on my Win98 system lives
in ...\python\lib\plat-win, and on NT in the same relative path.

And socket is built pretty much on the Windows native socket library.

> I'm running Python 1.5.2 on Windows
> There is an Apache/Linux intranet server in my LAN which IP addr/name is in
> "\winnt\system32\services\hosts" file (as usual when mixing Linux and
> Windows in a LAN).
> 
As has been pointed out, this is perhaps usual in a small LAN, but
there are many different ways to resolve addresses ... each to their
own.

> I can reach it by its name with IE or Netscape ("http://myintranetserver/")
> But when I make a python script with httplib with:
> 
> h = httplib.HTTP('myintranetserver')
> ...
> I got a "socket error : host not found"
> 
Well, this does look like a name resolution error, then.

> It works when replacing the name by its IP address:
> h = httplib.HTTP('192.168.0.15')
> 
This makes it look even MORE like a name resolution error.  Obviously
your IP connectivity is working OK.

> It seems that the HTTP __init__() looks for the DNS directly when other
> network applications look for the system native host naming scheme.
> 
> Is there a workaround to make a name/IP translation for hosts that are not
> recorded in the DNS.
> Of course I can make a parsing of the "\winnt\system32\services\hosts" file
> but if would be more comfortable to have the standard "httplib.HTTP" class
> doing it at my place. Hear me Python development crew ? 8o)
> 
Do you have "Enable LMHOSTS lookup" set in your TCP/IP DNS properties
tab?  This is a NetBIOS name you are trying to resolve, since you
haven't activated the DNS.  If you aren't running Samba on the Linux
boxes they aren't going to play well with the NetBIOS services, so I
understand why you want to use the hosts file to resolve their addresses.

Do you have NETBEUI support on the machine as well as TCP/IP?

> I don't know if the same bug/feature is in the Python/Unix and I'll check it
> when I shall have time.
> 
> Thanks in advance for a hint.

Well, no more than hints, but it's obvious you've got to head-scratching
now, so this might point to some areas you could look at.

Samba would save you frmm having to edit your hosts files...

Presumably "ping" works with both the host name and the IP address of
the target system?  Is it only the Python scoket library, or does *any*
code passing a host name into the native socket library fail?

regards
 Steve
-- 
Helping people meet their information needs with training and technology.
703 967 0887      sholden at bellatlantic.net      http://www.holdenweb.com/



More information about the Python-list mailing list