473,387 Members | 1,897 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Host resolution problems with socket module

I'm getting a rather bizarre error while using the socket module. If I
start out disconnected from the net and then connect while the program or
interpreter session is open, I do not always gain the ability to resolve
or connect to hosts by name. Here is the problematic scenario:

<Unplug network cable>
from socket import *
gethostbyname('google.com') # Fails as expected Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<string>", line 1, in connect
socket.gaierror: (-3, 'Temporary failure in name resolution')

<Plug network cable back in, verify that I am really connected, etc.>
gethostbyname('google.com') # Should succeed

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<string>", line 1, in connect
socket.gaierror: (-3, 'Temporary failure in name resolution')

After some testing, I believe that this behavior is dependent on whether
the first call to gethostbyname() succeeded or not. If the first call
succeeded, subsequent calls will either resolve the host or raise an
exception depending on the status of the internet connection. If the first
call failed (i.e. raised the above exception), subsequent ones will always
raise the same exception no matter if the connection has been restored.

I should also add that getaddrinfo() and .connect() on socket objects
both fail in the same way as gethostbyname(). Deleting the socket module
and then importing it again does not help, nor does calling
reload(socket). I've been testing this on Linux with both python 2.3 and
python 2.4. As far as I can tell, the only variable that affects this
behavior is the status of the connection at the time gethostbyname() is
first called.

Is there anything else I can do to fix this problem? Is it maybe a python
bug, or is it representative of some lower-level subtlety (e.g. in the C
libraries) that I'm unaware of? Has anyone else run into this before?

--
Jacob Lee
je****@uiuc.edu | www.nearestneighbor.net

Jul 21 '05 #1
0 1920

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Alexander N. Spitzer | last post by:
If I have a machine with 3 virtual IP addresses (192.168.1.), how can I start 3 instances of the same RMI application (each started with different properties/configs), each listening on the port...
0
by: Mikke Mattsson | last post by:
Does anoyne know how to get the socket-module to resolve numerical hostnames? The host address is not resolved correctly. >>> import socket >>> socket.getaddrinfo("3100",21) If I ping the...
7
by: none | last post by:
I want to determine the outside (non local, a.k.a. 127.0.0.x) ip addresses of my host. It seems that the socket module provides me with some nifty tools for that but I cannot get it to work...
0
by: Johann Blake | last post by:
I am using the TcpClient to connect to a web site. I then open a NetworkStream and read the contents that are being sent back. The problem is that I have no idea when the remote host is finished...
5
by: zxo102 | last post by:
Hi, I am doing a small project using socket server and thread in python. This is first time for me to use socket and thread things. Here is my case. I have 20 socket clients. Each client send a...
9
by: Irmen de Jong | last post by:
Hi, Recently I was bitten by an apparent bug in the BSD socket layer on Open VMS. Specifically, it appears that VMS defines MSG_WAITALL in socket.h but does not implement it (it is not in the...
3
by: abcd | last post by:
I have a linux machine (ip = 10.10.10.8), which can ping other machines on the same subnet...such as 10.10.10.1 10.10.10.2 10.10.10.5 10.10.10.6 10.10.10.254 If I use...
2
by: Mirko Vogt | last post by:
Hey, it seems that the socket-module behaves differently on unix / windows when a timeout is set. Here an example: # test.py import socket...
2
by: Richard Maher | last post by:
Hi, Can someone please tell me the strategy(ies) used by Java (the Security Manager or whatever) to determine if a given IP address conforms to the definition of the codebase from which an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.