5

Basically, I want to read the CPU temperature with 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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
ryan27968
  • 437
  • 3
  • 7
  • 14

2 Answers2

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.

Community
  • 1
  • 1
senshin
  • 10,022
  • 7
  • 46
  • 59
  • I have indeed tried that. I guess python isn't really the best language to use so i am going to try C++. Please check out the thread here: http://stackoverflow.com/questions/21060944/get-temperature-in-c-with-core-temp-sdk – ryan27968 Jan 11 '14 at 10:14
0

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

Primi
  • 9
  • 1
  • 3
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). - [From Review](/review/low-quality-posts/10325220) – President James K. Polk Nov 24 '15 at 23:24
  • 1
    @JamesKPolk I don't agree. I have no idea whether this solves the problem, or even makes sense, but I think this is a valid answer. If it turns out to be wrong, it should be downvoted, not flagged. – Fabio says Reinstate Monica Nov 24 '15 at 23:36