Re: [Tutor] Socket Error Handling Syntax
On 28.05.2013 19:25, sparkle Plenty wrote: I need to catch and handle 10057 exceptions when they occur and keep running. I know 10057 is a WinError, which is a subset of OSError, I just can't find the right syntax for it. I would appreciate some help on this one. I have neither Windows nor Python3.3 to test but according to the docs, winerror is an attribute of the OSError exception ( http://docs.python.org/3/library/exceptions.html?highlight=oserror#OSError ). Thus something like try: # some code except OSError as e: if e.winerror == 10057: # do error handling else: raise # re-raise any other error should work. Bye, Andreas ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Socket Error Handling Syntax
If I use an if statement, I cannot use continue after I do my error handling, so I am really trying to use the except errorname: instead of an if statement. Therefore, I have to find the correct error name to identify the 10057 condition to the interpreter, but thanks anyway, Andreas. On Tue, May 28, 2013 at 1:25 PM, sparkle Plenty sparkle.plenty12481...@gmail.com wrote: Python 3.3, Windows operating system: I am communicating with a device using a Python script and I am coding except clauses in my send and receive functions to handle a particular error. I can't find a WinError example, and I can't get the syntax right. I have researched this and tried the following: while not_sent: try: (my socket send code) except OSError.WinError.10057 (this failed) except OSError.WSAENOTCONN (this failed) except OSError.winerror.WSANOTCONN (this failed) I have another general except/as clause already coded and debugged for each function to catch unexpected errors and shut down. I need to catch and handle 10057 exceptions when they occur and keep running. I know 10057 is a WinError, which is a subset of OSError, I just can't find the right syntax for it. I would appreciate some help on this one. Thank you. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Socket Error Handling Syntax
On 05/28/2013 03:37 PM, sparkle Plenty wrote: If I use an if statement, I cannot use continue after I do my error handling, The presence of an if statement cannot affect whether or not a continue can work. If you give a concrete code example, somebody will be able to identify the confusion. And while you're at it, instead of saying this failed why not actually show us the traceback? Big difference between a name error and a type problem. so I am really trying to use the except errorname: instead of an if statement. Therefore, I have to find the correct error name to identify the 10057 condition to the interpreter, but thanks anyway, Andreas. except clauses do not work on error names they work on exception types. I don't use Windows, but I doubt if there's a separate exception type for 10057. Incidentally, if you ever do get one of those except clauses to fire, you're going to want an exception object. Something like: except OSError as theError: Then you can check the error code for anything you like. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Socket Error Handling Syntax
On 28.05.2013 21:37, sparkle Plenty wrote: If I use an if statement, I cannot use continue after I do my error handling, so I am really trying to use the except errorname: instead of an if statement. I think you haven't understood the code snippet I've posted. The if-statement is inside the except clause to check the Windows error number. Therefore, I have to find the correct error name to identify the 10057 condition to the interpreter, As Dave told you, the actual traceback will tell you the name of the exception. Bye, Andreas ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Socket Error Handling Syntax
On Tue, May 28, 2013 at 3:49 PM, Dave Angel da...@davea.name wrote: I don't use Windows, but I doubt if there's a separate exception type for 10057. Windows sockets error codes at or above 1 aren't mapped to POSIX error codes. Instead errno is set directly from winerror. So there's no reason to look at winerror in this case. Use the errno module: Windows: errno.errorcode[10057] # Windows-specific name 'WSAENOTCONN' errno.ENOTCONN 10057 Linux: errno.ENOTCONN 107 From MSDN, Windows Socket Error Codes: WSAENOTCONN 10057 Socket is not connected. A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using sendto) no address was supplied. Any other type of operation might also return this error—for example, setsockopt setting SO_KEEPALIVE if the connection has been reset. http://msdn.microsoft.com/en-us/library/ms740668 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor