Get CPU temperature in python on windows

夙愿已清 提交于 2019-12-12 08:58:00

问题


Basically i want to read the cpu temperature in python. Please explain in layman's terms as i have never done this on windows before nor have i had to work with wmi.

This is what I have at the moment:

import wmi
w = wmi.WMI(namespace="root\wmi")
temperature_info = w.MSAcpi_ThermalZoneTemperature()[0]
print temperature_info.CurrentTemperature

(i got this code from this thread: Accessing CPU temperature in python)

however, on running the script, i get this error:

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)>

what can i do to get this to work?


回答1:


According to the MSDN page on WMI Error Constants, the error you have received is:

WBEM_E_NOT_SUPPORTED
2147749900 (0x8004100C)

Feature or operation is not supported.

Presumably, then, your CPU does not provide temperature information through WMI. If your CPU doesn't expose this information, you're probably out of luck, at least as far as a straightforward solution in Python goes.

I assume you've tried the other option given in the answer you linked, using Win32_TemperatureProbe(); if you haven't, try it.




回答2:


Just execute as Admin. It's work for me.



来源:https://stackoverflow.com/questions/21053006/get-cpu-temperature-in-python-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!