Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
try except in wmi code
#1
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")
Reply
#2
What exception is raised when the connection is refused?
Reply
#3
  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
Reply
#4
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?
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020