Issue2742
Created on 2008-05-02 18:57 by mrm, last changed 2008-05-11 07:06 by georg.brandl.
| msg66103 (view) |
Author: Mike MacFaden (mrm) |
Date: 2008-05-02 18:57 |
|
the url
http://docs.python.org/lib/socket-example.html
gives an example that uses socket.getaddrinfo that has this code
HOST=''
...
for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC,
socket.SOCK_STREAM, 0, socket.AI_PASSIVE)
but this fails on freebsd 6.1/python 2.5 as follows
> /usr/home/mrm/s2.py(30)<module>()
-> for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC,
socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
(Pdb) p HOST
''
(Pdb) n
gaierror: (8, 'hostname nor servname provided, or not known')
> /usr/home/mrm/s2.py(30)<module>()
but setting
HOST=None
works fine.
either this is a doc bug or a code bug, your pick.
|
| msg66106 (view) |
Author: Martin v. Löwis (loewis) |
Date: 2008-05-02 19:32 |
|
What operating system are you using? It could be a bug in the operating
system as well.
|
| msg66132 (view) |
Author: Mike MacFaden (mrm) |
Date: 2008-05-02 23:55 |
|
Martin v. Löwis wrote:
> Martin v. Löwis <martin@v.loewis.de> added the comment:
>
> What operating system are you using? It could be a bug in the
> operating system as well.
hi martin,
what i've tested so far...
freebsd 6.2 - release 12 jan 2007
socket.gaierror: (8, 'hostname nor servname provided, or not known')
Red Hat Enterprise Linux Client release 5.1 (Tikanga), gnu/linux
2.6.18-53.el5
socket.gaierror: (-2, 'Name or service not known')
mike
|
| msg66511 (view) |
Author: Simon Cross (hodgestar) |
Date: 2008-05-10 11:20 |
|
This also affects Python 2.4 and 2.6 on Linux systems. Bug
http://bugs.python.org/issue2763 is a duplicate of this one.
The issue is that socketmodule.c doesn't convert empty strings to NULLs
before passing hptr through to the underlying system getaddrinfo(...).
The question is whether to fix the documentation and examples or the
socketmodule.c code.
|
| msg66512 (view) |
Author: Simon Cross (hodgestar) |
Date: 2008-05-10 11:33 |
|
Attached a patch to correct the getaddrinfo(...) documentation and the
code example in socket.rst.
|
| msg66513 (view) |
Author: Neil Muller (Neil Muller) |
Date: 2008-05-10 11:34 |
|
The documentation says:
For *host* and *port*, by passing either an empty string or ``None``,
you can pass ``NULL`` to the C API, so the documentation says it should
work.
This doesn't work because PyString_AsString retruns an empty string, not
NULL. The attached patch adds a check in socketmodule.c to fix this for
host and port.
It's highly debatable whether this is better than fixing the
documentation, though.
|
| msg66142 (view) |
Author: Martin v. Löwis (loewis) |
Date: 2008-05-03 06:53 |
|
I see. I just reread the getaddrinfo man page, and it says you must pass
NULL to leave host unspecified, so passing None is correct, and the
documentation is wrong.
|
| msg66606 (view) |
Author: Georg Brandl (georg.brandl) |
Date: 2008-05-11 07:06 |
|
Applied the documentation patch in r63039. Thanks for your efforts!
|
|
| Date |
User |
Action |
Args |
| 2008-05-11 07:06:33 | georg.brandl | set | status: open -> closed resolution: fixed messages:
+ msg66606 |
| 2008-05-11 07:04:36 | georg.brandl | link | issue2763 superseder |
| 2008-05-10 11:34:58 | Neil Muller | set | files:
+ socketmodule.diff nosy:
+ Neil Muller messages:
+ msg66513 |
| 2008-05-10 11:33:10 | hodgestar | set | files:
+ getaddrinfo-doesnt-treat-empty-string-as-none.diff keywords:
+ patch messages:
+ msg66512 |
| 2008-05-10 11:20:59 | hodgestar | set | nosy:
+ hodgestar messages:
+ msg66511 versions:
+ Python 2.6, Python 2.4 |
| 2008-05-03 06:53:23 | loewis | set | messages:
+ msg66142 |
| 2008-05-02 23:55:19 | mrm | set | messages:
+ msg66132 |
| 2008-05-02 19:32:07 | loewis | set | nosy:
+ loewis messages:
+ msg66106 |
| 2008-05-02 18:57:58 | mrm | create | |
|