Ok, I am pretty clueless here. I use the python WMI module to do the following command:
sj = wmi.Win32_ScheduledJob
sj.Create("cmd", 0x40000000, 32, 1, 0, "******153000.000000-420")
And that gives me the following error:
Traceback (most recent call last):
File "<pyshell#56>", line 1, in <module>
sj.Create("cmd", 0x40000000, 32, 1, 0, "******153000.000000-420")
File "C:\Python25\lib\site-packages\wmi.py", line 431, in __call__
handle_com_error ()
File "C:\Python25\lib\site-packages\wmi.py", line 241, in handle_com_error
raise klass (com_error=err)
x_wmi: <x_wmi: Unexpected COM Error (-2147352567, 'Exception occurred.', (0, u'SWbemProperty', u'Type mismatch ', None, 0, -2147217403), None)>
Ok, so could you tell me what arguments I am providing wrong? Please give me sample code. Thanks!
Does it make any difference if you format the StartTime argument with 8 initial * characters instead of 6?
I just notice that the Win32_ScheduledJob documentation seems to indicate 8 *s, in place of the omitted YYYYMMDD characters...
Related
I have defined a new derived dimension with
[molar_energy] = [energy] / [substance]
However, if I do the following it complains:
>>> UR.get_compatible_units('[molar_energy]')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/cedric/.local/share/virtualenvs/MatDB--uGOYMXa/lib/python3.9/site-packages/pint/registry.py", line 881, in get_compatible_units
equiv = self._get_compatible_units(input_units, group_or_system)
File "/Users/cedric/.local/share/virtualenvs/MatDB--uGOYMXa/lib/python3.9/site-packages/pint/registry.py", line 2082, in _get_compatible_units
ret = super()._get_compatible_units(input_units, group_or_system)
File "/Users/cedric/.local/share/virtualenvs/MatDB--uGOYMXa/lib/python3.9/site-packages/pint/registry.py", line 1835, in _get_compatible_units
ret = super()._get_compatible_units(input_units, group_or_system)
File "/Users/cedric/.local/share/virtualenvs/MatDB--uGOYMXa/lib/python3.9/site-packages/pint/registry.py", line 891, in _get_compatible_units
return self._cache.dimensional_equivalents[src_dim]
KeyError: <UnitsContainer({'[length]': 2, '[mass]': 1, '[substance]': -1, '[time]': -2})
I saw that there is a conversion included in a context but I don't use it. What I am doing wrong?
Thanks for your help
PS: logged issue https://github.com/hgrecco/pint/issues/1418
Just leaving the solution here for anyone who faces this issue as well.
I just added a made-up unit and it worked
# Molar Energy
[molar_energy] = [energy] / [substance]
mol_en = J / mol
I have a problem with the following function in python (where swap is a function that I have previously created and that works fine):
def swap (cards):
"""
>>> swap('FBFFFBFFBF')
'BFBBBFBBFB'
>>> swap('BFFBFBFFFBFBBBFBBBBFF')
'FBBFBFBBBFBFFFBFFFFBB'
>>> swap('FFBFBFBFBFBFBFBBFBFBFBFBBFBFBBFBF')
'BBFBFBFBFBFBFBFFBFBFBFBFFBFBFFBFB'
"""
invert=""
for i in cards:
if i is "B":
invert+="F"
else:
invert+="B"
return (invert)
def swap2 (cards):
"""
>>> next('FBFFFBFFBF')
'FFBBBFBBFF'
>>> next('BFFBFBFFFBFBBBFBBBBFF')
'FBBFBFBBBFBFFFBFFFFFF'
>>> next('FFBFBFBFBFBFBFBBFBFBFBFBBFBFBBFBF')
'FFFBFBFBFBFBFBFFBFBFBFBFFBFBFFBFF'
"""
indices=""
for pos, i in enumerate(cards):
if i =="B":
indices+=str(pos)
first= int(indices[0])
last= int(indices[-1])
prefix= cards [:first]
middle= cards [first:last+1]
suffix= cards [last+1:]
middle2=swap(middle)
return (prefix+middle2+suffix)
def turns (cards):
"""
>>> turns('FBFFFBFFBF')
3
>>> turns('BFFBFBFFFBFBBBFBBBBFF')
6
>>> turns('FFBFBFBFBFBFBFBBFBFBFBFBBFBFBBFBF')
14
"""
turn=0
while cards != 'F'*len(cards):
cards=swap2(cards)
turn+=1
return (turn)
if __name__ == '__main__':
import doctest
doctest.testmod()
when I run this function it works fine but if I use doctest to see if there are mistakes it tells me:
TypeError: 'str' object is not an iterator
I don't know where this error comes from.
Can anyone help me?
complete output of the doctest:
File "C:\Users\manuel\Documents\Gent MaStat\programming and algorithms\workspace_python\homeworks\Week 5\looking_up.py", line 25, in __main__.swap2
Failed example:
next('FBFFFBFFBF')
Exception raised:
Traceback (most recent call last):
File "C:\Users\manuel\Anaconda3\lib\doctest.py", line 1321, in __run
compileflags, 1), test.globs)
File "<doctest __main__.swap2[0]>", line 1, in <module>
next('FBFFFBFFBF')
TypeError: 'str' object is not an iterator
**********************************************************************
File "C:\Users\manuel\Documents\Gent MaStat\programming and algorithms\workspace_python\homeworks\Week 5\looking_up.py", line 27, in __main__.swap2
Failed example:
next('BFFBFBFFFBFBBBFBBBBFF')
Exception raised:
Traceback (most recent call last):
File "C:\Users\manuel\Anaconda3\lib\doctest.py", line 1321, in __run
compileflags, 1), test.globs)
File "<doctest __main__.swap2[1]>", line 1, in <module>
next('BFFBFBFFFBFBBBFBBBBFF')
TypeError: 'str' object is not an iterator
**********************************************************************
File "C:\Users\manuel\Documents\Gent MaStat\programming and algorithms\workspace_python\homeworks\Week 5\looking_up.py", line 29, in __main__.swap2
Failed example:
next('FFBFBFBFBFBFBFBBFBFBFBFBBFBFBBFBF')
Exception raised:
Traceback (most recent call last):
File "C:\Users\manuel\Anaconda3\lib\doctest.py", line 1321, in __run
compileflags, 1), test.globs)
File "<doctest __main__.swap2[2]>", line 1, in <module>
next('FFBFBFBFBFBFBFBBFBFBFBFBBFBFBBFBF')
TypeError: 'str' object is not an iterator
def swap2 (cards):
"""
>>> next('FBFFFBFFBF')
'FFBBBFBBFF'
>>> next('BFFBFBFFFBFBBBFBBBBFF')
'FBBFBFBBBFBFFFBFFFFFF'
>>> next('FFBFBFBFBFBFBFBBFBFBFBFBBFBFBBFBF')
'FFFBFBFBFBFBFBFFBFBFBFBFFBFBFFBFF'
"""
# …
The function is called swap2 but within the doctests, you are using next which happens to be a built-in function that does something completely different. That’s why you are seeing that error.
At times like this, it’s really important to actually look at the error messages. It clearly told you what was called:
File "<doctest __main__.swap2[0]>", line 1, in <module>
next('FBFFFBFFBF')
So if you don’t know where that was supposed to come from, then check out the error message. Doctest will tell you what it is executing: swap2[0], swap2[1], etc. tells you the function name the docstring that is being executed is by doctest and which test case it is (0 is the first, 1 the second etc.). It even gives you the line number (within the doctest case) where the error appeared, and of course the line that was causing the error. So use that information to go to the problematic code, and figure out what the problem is.
Using the wifi package, here is what I did:
>>> cell = Cell.all('wlan0')[0]
>>> print cell
>>> scheme = Scheme.for_cell('wlan0', 'home', cell)
When I print cell it prints the ssid. When I run scheme = Scheme.for_cell('wlan0', 'home', cell). It gives the error
>>> scheme = Scheme.for_cell('wlan0', 'home', cell)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/aaeronn/virt_proj/wifi_hack/local/lib/python2.7/site-packages/wifi/scheme.py", line 110, in for_cell
return cls(interface, name, configuration(cell, passkey))
File "/home/aaeronn/virt_proj/wifi_hack/local/lib/python2.7/site-packages/wifi/scheme.py", line 23, in configuration
if len(passkey) != 64:
TypeError: object of type 'NoneType' has no len()
Whats wrong ? Where should I enter the password for that ssid?
The documentation for wifi.Scheme.for_cell says it takes a passkey argument:
classmethod for_cell(interface, name, cell, passkey=None)
So with some passkey, you would call
scheme = Scheme.for_cell('wlan0', 'home', cell, passkey)
Looking at the source code for that package, the TypeError raised there is a bug, or at least a sign of hasty design.
I am trying to get some system information from Pythons WMI module however allot of the methods mention online don't seem to be working. I know it is easier to do it in other languages but I want to try and do this in Python for reasons.
I have tried using the Win32_TemperatureProbe() method but I get a return value of None. I have also tried the MSAcpi_ThermalZoneTemperature() and the error for that is below. I have been doing my research and can't seem to find any alternative methods or fixes to these errors. There seem to be allot of threads open but none solved.
Here is my current code:
import wmi, platform
#Initiating WMI
c = wmi.WMI(namespace="root\\wmi")
#Setting variables
drive_letter, free_space = [], []
stats = {}
#Getting basic infromation
print(platform.processor())
print(c.MSAcpi_ThermalZoneTemperature()[0].CurrentTemperature/10.0)-273.15
for disk in c.Win32_LogicalDisk(["Caption","FreeSpace"], DriveType=3):
free_space_GB = round(int((disk.FreeSpace))/1073741824, 2)
drive_letter.append(str(disk.Caption))
free_space.append(str(free_space_GB))
stats = {"Free Space":free_space, "Drive Letter":drive_letter}
print(stats)
and here is the output I get when running this code:
Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\wmi.py", line 817, in query
return self._namespace.query (wql, self, fields)
File "C:\Python34\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:\Python34\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:\Python34\lib\site-packages\win32com\client\dynamic.py", line 247, in __getitem__
return self._get_good_object_(self._enum_.__getitem__(index))
File "C:\Python34\lib\site-packages\win32com\client\util.py", line 37, in __getitem__
return self.__GetIndex(index)
File "C:\Python34\lib\site-packages\win32com\client\util.py", line 53, in __GetIndex
result = self._oleobj_.Next(1)
pywintypes.com_error: (-2147217396, 'OLE error 0x8004100c', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Brandyn\Desktop\Performance_monitor.py", line 12, in <module>
print(c.MSAcpi_ThermalZoneTemperature()[0].CurrentTemperature/10.0)-273.15
File "C:\Python34\lib\site-packages\wmi.py", line 819, in query
handle_com_error ()
File "C:\Python34\lib\site-packages\wmi.py", line 241, in handle_com_error
raise klass (com_error=err)
wmi.x_wmi: <x_wmi: Unexpected COM Error (-2147217396, 'OLE error 0x8004100c', None, None)>
When I change the namespace to null, the error changes to this:
Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\wmi.py", line 1145, in __getattr__
return self._cached_classes (attribute)
File "C:\Python34\lib\site-packages\wmi.py", line 1156, in _cached_classes
self._classes_map[class_name] = _wmi_class (self, self._namespace.Get (class_name))
File "<COMObject winmgmts:>", line 3, in Get
File "C:\Python34\lib\site-packages\win32com\client\dynamic.py", line 282, in _ApplyTypes_
result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'SWbemServicesEx', 'Not found ', None, 0, -2147217406), None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Brandyn\Desktop\Performance_monitor.py", line 12, in <module>
print(c.MSAcpi_ThermalZoneTemperature()[0].CurrentTemperature/10.0)-273.15
File "C:\Python34\lib\site-packages\wmi.py", line 1147, in __getattr__
return getattr (self._namespace, attribute)
File "C:\Python34\lib\site-packages\win32com\client\dynamic.py", line 522, in __getattr__
raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: winmgmts:.MSAcpi_ThermalZoneTemperature
Is there a fix to this method or is there another viable alternative or should I just simply stop this and focus on a different language?
I had the same issue.
For Win32_LogicalDisk, you need to replace namespace root\\wmi with root\\cimv2.
Then it worked for me on Win7.
For MSAcpi_ThermalZoneTemperature, I have not found a solution. The object looks as follows
>>> print c.MSAcpi_ThermalZoneTemperature
[dynamic: ToInstance, provider("WMIProv"), WMI, guid("{A1BC18C0-A7C8-11d1-BF3C-00A0C9062910}")]
class MSAcpi_ThermalZoneTemperature : MSAcpi
{
[key, read] string InstanceName;
[read] boolean Active;
[WmiDataId(1), read] uint32 ThermalStamp;
[WmiDataId(2), read] uint32 ThermalConstant1;
[WmiDataId(3), read] uint32 ThermalConstant2;
[WmiDataId(4), read] uint32 Reserved;
[WmiDataId(5), read] uint32 SamplingPeriod;
[WmiDataId(6), read] uint32 CurrentTemperature;
[WmiDataId(7), read] uint32 PassiveTripPoint;
[WmiDataId(8), read] uint32 CriticalTripPoint;
[WmiDataId(9), read] uint32 ActiveTripPointCount;
[WmiDataId(10), MissingValue(0), read, MAX(10)] uint32 ActiveTripPoint[];
};
BUT c.MSAcpi_ThermalZoneTemperature.CurrentTemperature returns None.
Interesting is if we run folliwing code
import win32com.client
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\WMI")
colItems = objSWbemServices.ExecQuery("SELECT * FROM MSAcpi_ThermalZoneTemperature")
print repr(colItems)
print len(colItems)
then calling print repr(colItems) returns <COMObject <unknown>>
and calling print len(colItems) generates an exception:
Traceback (most recent call last):
File "get_wmi_test1.py", line 45, in <module>
print len(colItems)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 228, in
__len__
return self._oleobj_.Invoke(dispid, LCID, invkind, 1)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'SWbemObjectSet'
, u'Not supported ', None, 0, -2147217396), None)
I looked a bit around and seems to be more complex issue. Look here:
MSAcpi_ThermalZoneTemperature not showing temperature
How to enable WMI on windows 7
I get this error on running my module gasprop. I do not understand what the error means and how to fix it:
import gasprop
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "gasprop.py", line 13, in <module>
sheet = wb.Sheets("Input1")
File "C:\Python27\lib\site-packages\win32com\gen_py\00020813-0000-0000-C000-000000000046x0x1x6\Sheets.py", line 113, in __call__
ret = self._oleobj_.InvokeTypes(0, LCID, 2, (9, 0), ((12, 1),),Index
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147352565), None)
And here is my module gasprop:
import win32com.client, os
xl = win32com.client.gencache.EnsureDispatch("Excel.Application")
thisdir = os.getcwd()
wb = xl.Workbooks.Open(thisdir+"/Input1.xlsx")
sheet = wb.Sheets("Input1")
......
def megaverify(self):
listtr,listp=[],[]
for i in range(16):
tr=float(sheet.Range("D"+str(5+i)).Value)
p=float(sheet.Range("C"+str(5+i)).Value)
listtr.append(tr);listp.append(p)
return tr, p
You can use this teсhnique to get more information about error:
import win32api
e_msg = win32api.FormatMessage(-2147352565)
print e_msg.decode('CP1251')
The message you get means that your excel file does not have a sheet with the name "Input1". You can simply rename it.
The error occurred because the sheet I wanted to call from the excel workbook did not match the name I was referencing it by in my python code. My sheet was actually Sheet1 (by default in excel) but I was calling a sheet Input1 as seen in line 5 of my module gasprop. The mismatch in names caused this error.