Bug in socket.connect_ex() implementation or docs ?!

Fredrik Lundh fredrik at pythonware.com
Thu May 6 18:31:47 EDT 1999


Barry A. Warsaw wrote:
> Note that there's an easy workaround: call gethostbyname first
> yourself and catch any exceptions there.  If valid, pass the resulting
> IP address to connect_ex(), e.g.:
> 
> try:
>     ip = socket.gethostbyname('somemachine')
>     conn = s.connect_ex(ip, PORT)
> except socket.error:
>     pass
> 
> Does this defeat too much of the purpose of connect_ex()?

looks to me as if the easiest way is to change the documentation:

    connect_ex (address)

    Like connect(address), but return an error indicator if the connect
    call fails, instead of raising an exception. If anything else goes wrong
    (for example, if the host name doesn't exist), this works exactly like
    connect(address).

or something like that.

</F>





More information about the Python-list mailing list