How to capture Exception in python scripting for new_server function?

I tried to capture the exception case with the following code when the function of new_server is called with wrong scrpting server port ID or password. 

========================================================================================

try:
   s_o, g_o = new_server('localhost', outputport, password=outpass, error_mode=(RAISE))
except:
   msgbox("Warning: the supplied scripting server port ID or password is not correct.")
   sys.exit()

========================================================================================

However, it seems that the exception does happen even when I provide the correct port ID and password. Not sure how to get it to work. Thanks for help in advance. 

Also, is it possible tp reset the port ID / password for the scripting server within the python code in the middle of the process? For example, after some tasks are completed, those settings will be re-set for the following tasks. 

  • Hi Bo Xu,

    The code to check this would ideally look like this:

    from plxscripting.easy import *
    from easygui import msgbox
    
    outputport = 10001
    outputpass = r'YOURPASSWORD'
    
    s_o, g_o = new_server('localhost', outputport, password=outputpass)
    if not s_o.active:
        msgbox("Warning: the supplied scripting server port ID or password is not correct.")
        sys.exit()
    

    If you want to reset the port/password in your code, you have to call the newserver with the new port number/password to set Output's server object (s_o) and Outpuyt's global object (g_o).

    Note that if you call Output from the PLAXIS Input program, like when viewing a phase, it will return the port number that is being assigned to Output.

    Python example

    from plxscripting.easy import *
    from easygui import msgbox
    
    inputport = 10000
    plaxispass = r'YOURPASSWORD'
    
    # initiate the Input server object
    s_i, g_i = new_server('localhost', inputport plaxispass)
    
    # call viewing results from the Input program
    outputport, = g_i.view(g_i.Phase_2))
    
    # initiate the Output server object
    s_o, g_o = new_server('localhost', outputport, password=plaxispass)
    if not s_o.active:
        msgbox("Warning for PLAXIS Output: the supplied scripting server port ID or password is not correct.")
        sys.exit()
    

    Answer Verified By: Micha van der Sloot