try except in wmi code - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: try except in wmi code (/thread-36354.html) |
try except in wmi code - ilknurg - Feb-10-2022 How can i use try except in this code script? I want to print an error message when the connection refused. Sorry for this simple question but im a newbie :( #!/usr/bin/python3 #!/usr/bin/python import wmi_client_wrapper as wmi wmic = wmi.WmiClientWrapper(username="Administrator",password="Ares4382)",host="192.168.1.200",) output = wmic.query("SELECT * FROM Win32_Processor") RE: try except in wmi code - deanhystad - Feb-10-2022 What exception is raised when the connection is refused? RE: try except in wmi code - ilknurg - Feb-11-2022 RAN: /usr/local/bin/wmic --delimiter= --user= % // --namespace=//./root/cimv2 SELECT UserName FROM Win32_ComputerSystem STDOUT: [librpc/rpc/dcerpc_connect.c:337:dcerpc_pipe_connect_ncacn_ip_tcp_recv()] failed NT status (c00000b5) in dcerpc_pipe_connect_ncacn_ip_tcp_recv [librpc/rpc/dcerpc_connect.c:828:dcerpc_pipe_connect_b_recv()] failed NT status (c00000b5) in dcerpc_pipe_connect_b_recv [wmi/wmic.c:196:main()] ERROR: Login to remote object. STDERR: NTSTATUS: NT_STATUS_IO_TIMEOUT - NT_STATUS_IO_TIMEOUTı get this error. I want to get it in except statement. Because i want to save it with linux logger into database RE: try except in wmi code - deanhystad - Feb-11-2022 There is no exception, so there is nothing to catch. You can capture stdout and look for "failed NT status". You can capture stderr and look for anything? |