Py学习  »  Python

如何将代码脚本输出为python异常消息?

ayayay • 3 年前 • 1275 次点击  

我有下面的代码。当我运行它时,会出现一个错误:

*

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

我想在我的异常中获取此错误消息。然后,我使用linux logger并将其保存到我的数据库中。如何将此输出作为异常消息获取?

#!/usr/bin/python3
#!/usr/bin/python

import wmi_client_wrapper as wmi

try:
  wmic = wmi.WmiClientWrapper(username="Administrator",password="Abc",host="192.168.1.2",)
  output = wmic.query("SELECT * FROM Win32_Processor")
  print(output)
except:
  print("An exception occurred")
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/131054
 
1275 次点击  
文章 [ 2 ]  |  最新文章 3 年前