Why is this working? -
import wmi w = wmi.WMI(namespace="root\OpenHardwareMonitor") temperature_infos = w.Sensor() for sensor in temperature_infos: if sensor.SensorType==u'Temperature': if sensor.Name=='CPU Package': print( sensor.Name ) print( sensor.Value )but this isn't working-
import wmi w = wmi.WMI(namespace='root\\wmi') temperature = w.MSAcpi_ThermalZoneTemperature()[0] temperature = int(temperature.CurrentTemperature / 10.0 - 273.15) print( temperature )I am getting this error when I run the second code -
Error:Traceback (most recent call last):
File "C:\Users\Aryan\AppData\Local\Programs\Python\Python36\lib\site-packages\wmi.py", line 817, in query
return self._namespace.query (wql, self, fields)
File "C:\Users\Aryan\AppData\Local\Programs\Python\Python36\lib\site-packages\wmi.py", line 1009, in query
return [ _wmi_object (obj, instance_of, fields) for obj in self._raw_query(wql) ]
File "C:\Users\Aryan\AppData\Local\Programs\Python\Python36\lib\site-packages\wmi.py", line 1009, in <listcomp>
return [ _wmi_object (obj, instance_of, fields) for obj in self._raw_query(wql) ]
File "C:\Users\Aryan\AppData\Local\Programs\Python\Python36\lib\site-packages\win32com\client\dynamic.py", line 252, in __getitem__
return self._get_good_object_(self._enum_.__getitem__(index))
File "C:\Users\Aryan\AppData\Local\Programs\Python\Python36\lib\site-packages\win32com\client\util.py", line 37, in __getitem__
return self.__GetIndex(index)
File "C:\Users\Aryan\AppData\Local\Programs\Python\Python36\lib\site-packages\win32com\client\util.py", line 53, in __GetIndex
result = self._oleobj_.Next(1)
pywintypes.com_error: (-2147217405, 'OLE error 0x80041003', None, None)
During handling of the above exception, another exception occurred:Error:Traceback (most recent call last):
File "C:\Users\Aryan\Desktop\Temperature code.py", line 4, in <module>
temperature = w.MSAcpi_ThermalZoneTemperature()[0]
File "C:\Users\Aryan\AppData\Local\Programs\Python\Python36\lib\site-packages\wmi.py", line 819, in query
handle_com_error ()
File "C:\Users\Aryan\AppData\Local\Programs\Python\Python36\lib\site-packages\wmi.py", line 241, in handle_com_error
raise klass (com_error=err)
wmi.x_access_denied: <x_wmi: Unexpected COM Error (-2147217405, 'OLE error 0x80041003', None, None)>
I don't know what this means. I am new to python and I need to find the temperature of my laptop for a project I am working on. I know I am making some mistake but cannot figure what mistake I am making. To all the experienced guys out there, can you help me? Any help would be appreciated.Moderator Larz60+: Added error tags