报错信息
Traceback (most recent call last):
File "C:\Users\Administrator\PycharmProjects\pandas\venv\Lib\site-packages\wmi.py", line 1320, in connect
obj = connect_server(
^^^^^^^^^^^^^^^
File "C:\Users\Administrator\PycharmProjects\pandas\venv\Lib\site-packages\wmi.py", line 1453, in connect_server
ConnectServer(
File "<COMObject WbemScripting.SWbemLocator>", line 3, in ConnectServer
File "C:\Users\Administrator\PycharmProjects\pandas\venv\Lib\site-packages\win32com\client\dynamic.py", line 366, in _ApplyTypes_
result = self._oleobj_.InvokeTypes(
^^^^^^^^^^^^^^^^^^^^^^^^^^
pywintypes.com_error: (-2147352567, '发生意外。', (0, 'SWbemLocator', 'RPC 服务器不可用。 ', None, 0, -2147023174), None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Administrator\PycharmProjects\pandas\wintest.py", line 8, in <module>
wmiServer = wmi.WMI(IP, user=username, password=password)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Administrator\PycharmProjects\pandas\venv\Lib\site-packages\wmi.py", line 1354, in connect
handle_com_error()
File "C:\Users\Administrator\PycharmProjects\pandas\venv\Lib\site-packages\wmi.py", line 258, in handle_com_error
raise klass(com_error=err)
wmi.x_wmi: <x_wmi: Unexpected COM Error (-2147352567, '发生意外。', (0, 'SWbemLocator', 'RPC 服务器不可用。 ', None, 0, -2147023174), None)>
处理方案
1,查看wmi服务是否启动
Windows Management Instrument
DCOM Server Process Launcher
Remote Procedure Call(RPC)
RPC Endpoint Mapper
2,查看端口访问是否被禁用
wmi使用的端口是135端口,对于Windows2008及更高版本的服务器,请确保防火墙上的端口49152至65535已打开(随机端口)
防火墙配置允许目标服务器访问一下端口
135, 49152-65535