Make python print all exceptions in English

1

Currently my installation of python 2.7 prints some, but not all error messages in Spanish

socket.error: [Errno 10054] Se ha forzado la interrupci¾n de una conexi¾n existente por el host remoto

How can I make all exceptions be displayed in English?

    
asked by user3344399 13.08.2018 в 06:30
source

1 answer

1

Given that you get interrupci¾n instead of interrupción I think I'm not wrong to think you're in Windows.

Python does not offer mechanisms to translate the messages of its exceptions, which always come in English. Apparently the error message in this case is specific to Windows, which is the one that handles "below" the sockets. Probably python, to ignore the particularities of the platform on which it is running, is limited to printing the error code number and the explanatory message that Windows reports.

You can change the default Windows language, and that will surely change the message.

You can capture the socket.error exception, examine the message string looking for a certain numeric code and raise another exception with the translated message. Something like this:

try:
     # Codigo que maneja sockets
except socket.error, e:
    if 'Errno 10054' in str(e):
        raise socket.error("[Errno 10054] An existing connection was forcibly closed by the remote host")

But better still you should not do anything . It is assumed that exception messages should never be visible to the end user, since your application must handle those exceptions appropriately (except perhaps during the development phase, in which the language in which they appear is not very important). ).

    
answered by 13.08.2018 в 10:41