Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Temperature Code help?
#1
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
Reply
#2
Open the Command prompt as administrator and run the script from there
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
w = wmi.WMI(namespace='root\\wmi')
Change To:
w = wmi.WMI(namespace=r'root\wmi', privileges=["Security"])
Run code as administrator,testet Win-10 Python 36 okay for me.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help gathering Temperature from API response road102 5 1,019 Dec-16-2022, 08:30 PM
Last Post: road102
  get data (temperature and humidity) from DHT22 into CSV and sending them over the net apollo 0 3,797 Apr-16-2021, 07:49 PM
Last Post: apollo
  monitoring the temperature of the CPU with Python apollo 2 8,527 Apr-13-2021, 05:39 PM
Last Post: apollo
  print CPU temperature samuelbachorik 12 5,922 Aug-04-2020, 03:28 PM
Last Post: Axel_Erfurt
  Read temperature once mada72 2 2,739 Apr-28-2019, 07:18 PM
Last Post: mada72
  Code Wireless Temperature sensor and send sensor readings to google sheet jenkins43 0 2,168 Nov-29-2018, 12:44 PM
Last Post: jenkins43
  Importing a temperature converting module RedSkeleton007 2 7,925 Nov-12-2017, 01:20 PM
Last Post: sparkz_alot
  Temperature value code 20AJ0931 10 13,373 Mar-19-2017, 11:05 PM
Last Post: 20AJ0931

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020