rya*_*968 6 python cpu wmi temperature python-2.7
基本上,我想用Python读取CPU温度。请用通俗易懂的方式解释一下,因为我以前从未在 Windows 上这样做过,也没有使用过wmi.
这就是我现在所拥有的:
import wmi
w = wmi.WMI(namespace="root\wmi")
temperature_info = w.MSAcpi_ThermalZoneTemperature()[0]
print temperature_info.CurrentTemperature
Run Code Online (Sandbox Code Playgroud)
(我从这个线程中得到了这段代码:Accessing CPU temp in python)
但是,在运行脚本时,我收到此错误:
Traceback (most recent call last):
File "C:\Users\Ryan\Desktop\SerialSystemMonitor", line 4, in <module>
temperature_info = w.MSAcpi_ThermalZoneTemperature()[0]
File "C:\Python27\lib\site-packages\wmi.py", line 819, in query
handle_com_error ()
File "C:\Python27\lib\site-packages\wmi.py", line 241, in handle_com_error
raise klass (com_error=err)
x_wmi: <x_wmi: Unexpected COM Error (-2147217396, 'OLE error 0x8004100c', None, None)>
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能让它发挥作用?