Sockets

Brian Quinlan brian at sweetapp.com
Sat Jun 2 16:07:14 EDT 2001


Adonis wrote:

> *newbie question*

> how can i check for errors when using the socket module?
> errors like: unable to connect; insufficient memory etc.

See http://www.python.org/doc/current/lib/module-socket.html for more
details...

The basic answer is that the socket module uses exception to indicate
errors. The exception thrown will a socket.error and it's value will
"...either a string telling what went wrong or a pair (errno, string)
representing an error returned by a system call". Here is an example:

>>> try:
...     socket.socket(1,2,3)
... except Exception,e:
...     print e.args
(10047, 'Address family not supported')





More information about the Python-list mailing list