Also, how would I write the try exception block if I did import socket ? Can someone also explain the difference in the imports. I would like to catch the socket timeout (preferably in an exception). URLError: can catch it but I need to distinguished between a . If you have chosen a random, but vali IP address and port, socket.
Note that if a timeout is explicitly set for the socket, the exception will be socket. This exception is raised when a timeout occurs on a socket which has had timeouts enabled via a prior call to settimeout().
So, all you need to do is put the socket. Thanks, that works fine, but I don’t understand why the exception . Low-level networking interface — Python 3. A subclass of OSError , this exception is raised when a timeout occurs on a socket which has had . In Python, all exceptions must be instances of a class that derives from. This page provides python code examples for socket. Post your question and get tips solutions from a.