test_socket.py failure

x2164 at mailcity.com x2164 at mailcity.com
Tue Feb 15 13:08:54 EST 2005


x2164 at mailcity.com wrote:

>      hi all,

>      Linux 2.4.28
>      Glibc 2.2.5
>      gcc   2.95.3


>      I'm new to Python.

>      I've compiled Python 2.4 from tar file.

>      When running 'make test' i'm getting a failure
>      in test_socket.

>      Running './python Lib/test/test_socket.py' yields:


> ======================================================================
> ERROR: testGetServBy (__main__.GeneralModuleTests)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>   File "Lib/test/test_socket.py", line 330, in testGetServBy
>     port2 = socket.getservbyname(service)
> error: service/proto not found

> ----------------------------------------------------------------------
> Ran 58 tests in 3.826s



>      The value of 'service' was "daytime".

>      After much hand wringing, editing, and use of 'print'
>      statements i commented out line 330,
>      '# port2 = socket.getservbyname(service)' and replaced it
>      with the line 'port2 = port'.

>      Running './python Lib/test/test_socket.py' now yields:


> testGetServBy (__main__.GeneralModuleTests) ... ok
>    .
>    .
>    .
> ----------------------------------------------------------------------
> Ran 58 tests in 5.181s

> OK

>  
>      Located the code for 'socket_getservbyname' in 
>      'Modules/socketmodule.c' where the call to the glibc
>      function 'getservbyname' is made: 

>      Py_BEGIN_ALLOW_THREADS
>      sp = getservbyname(name, proto);
>      Py_END_ALLOW_THREADS
>      if (sp == NULL) {
>              PyErr_SetString(socket_error, "service/proto not found");
>              return NULL;
>      }

>  
>      The only call of socket.getservbyname that failed was when
>      it was passed the single argument.  Since the error message
>      "service/proto not found" seems to only be generated upon
>      failure of gibc's 'getservbyname' could it be that 
>      'PyArg_ParseTuple(args, "s|s:getservbyname", &name, &proto)'
>      generates values for 'name' and/or 'proto' that cause the
>      failure?

>      My search for prior reports of failure at line 330 found
>      a mention of problems at line 331.

>      Well, at any rate, if someone could point me down the 
>      correct path on this i would appreciate it.


>      pete jordan
>      x2164 -> mailcity.com
>      -> equals at symbol



>
> http://www.die.net/doc/linux/man/man3/getservbyname.3.html
>

     The above link was provide by Nick Coghlan. 

     Thanks Nick.

     Well if the man page says it, then it must be so.

     By way of follow up i wanted to let you know that i think
     i've found the reason why i was getting the getservbyname
     behaviour that i described.

     In my /etc/nsswitch.conf file the original line for
     scanning the /etc/services file was:

         services:   nisplus [NOTFOUND=return] db files

     The nisplus module was being used first to scan the file
     and it apparently returns 'NOTFOUND' when proto is NULL.
     '[NOTFOUND=return]' then stops any of the other two
     services, 'db' and 'files', from being used to scan 
     the 'services' file.  I changed the 'services:' line to:

         services:   nisplus db files

     and now if proto is NULL the first line in the 'services' 
     file, matching the service argument passed to 
     getservbyname, is passed back.  This seems to be consistent 
     behaviour with the man page link above.

     I'm not sure removing '[NOTFOUND=return] ' is 100% 
     correct but from information in the libc info page i 
     think it will do.

     Later i'll post this as a followup to comp.lang.python 
     thread in case someone else might have the problem.

     Thanks for the help.


     pete jordan
     x2164 AT mailcity com






More information about the Python-list mailing list