Type error - win32com\client - __getattr__

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
hlech65730
User
Beiträge: 9
Registriert: Samstag 10. Februar 2018, 19:28

Hallo @ all,

ich habe da mal wieder so ein sch.. Problem mit dem Windows Client, vermute ich. Mein Code ist übersichtlich :

Code: Alles auswählen

from CANOE_Interface import *

canoe_inst = CANoe()

def main(args):
	canoe_inst.Start()
	canoe_inst.SetSysVar('SmokeTest','svTestStart',1)

	return 0

if __name__ == '__main__':
    import sys
    sys.exit(main(sys.argv))

was ich da als Import verwende stammt aus dem CANoe_Interface.py ( ist vielleicht noch unter Python 2.x entwickelt worden). Das ist ein "bißchen" zu groß um's als Code hier reinzukopieren, aber ich werde zumindest die betroffenen Klassen und Methoden reinkopieren ( kann man hier im Forum keine Files hochladen, habe nichts gesehen ? ).
Folgende Fehlermeldung kommt :


Traceback (most recent call last):
File "CANoe_Test.py", line 37, in <module>
sys.exit(main(sys.argv))
File "CANoe_Test.py", line 31, in main
canoe_inst.SetSysVar('SmokeTest','svTestStart',1)
File "D:\DSUsers\uid02589\PLAST\CANOE_Interface.py", line 439, in SetSysVar
varType = self.GetSysVarType(varNamespace, varName)
File "D:\DSUsers\uid02589\PLAST\CANOE_Interface.py", line 415, in GetSysVarType
varType = self.Application.System.Namespaces(varNamespace).Variables(varName).Type
File "C:\LegacyApp\Python36\lib\site-packages\win32com\client\__init__.py", line 473, in __getattr__
raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr))
AttributeError: '<win32com.gen_py.CANoe 10.0 Type Library.IVariable instance at 0x2152718570720>' object has no attribute 'Type'

------------------
(program exited with code: 1)

Drücken Sie eine beliebige Taste . . .

Was "CANoe_Test.py", line 37, in <module> sys.exit(main(sys.argv)) mit dem Rest der Meldungen zu tun hat weiß ich nicht, deshalb hier mal weiter :

2. Bezieht sich auf die Zeile canoe_inst.SetSysVar('SmokeTest','svTestStart',1) , die ersten beide strings sind ok , aber die 1 sollte eine IntVar sein und das scheint das Problem zu sein.
Eine Etage tiefer beim CANoe_Interface.py dann :

Code: Alles auswählen

  def SetSysVar(self, varNamespace, varName, varVal):
        #Syntax SetSysVarType(varNamespace, varName, varVal) 
        #Description Sets the value of a SystemVariable object. 
        #Parameters 
        #1. varNamespace (string) The namespace where the system variable is stored.
        #2. varName (string) The name of the system variable.
        #3. varVal (varying) The value that is to be assigned to the system variable. 
        #Return Values - 
        #Example can_inst.SetSysVar('SecurityAccess', 'TesterPresentEnable', 1) 
        #or:
        #can_inst.SetSysVar('CodingParameters::CP_F198_Param', 'ByteArray', (48, 49, 50, 51, 52, 53))
        varType = self.GetSysVarType(varNamespace, varName) [b] Kommentar: hier Zeile 439 ! [/b]
        if (varType is 'Integer' or 'Float' or 'String' or 'LongLong'):
            self.Application.System.Namespaces(varNamespace).Variables(varName).Value = varVal
        elif (varType is 'Float Array' or 'Integer Array' or 'Byte Array' or 'Generic Array'):
            self.Application.System.Namespaces(varNamespace).Variables(varName).Value = varVal
        elif (varType is 'Struct'):
            self.Application.System.Namespaces(varNamespace).Variables(varName).Value = varVal
        else: #(varType is 'Invalid')
            print("Invalid System Variable Type!")
das Ganze gibt's dann nochmal bei der Methode GetSysVar(... aber gleiche Ursache , die scheint dann im win32com client zu liegen ( hier die Stelle in der __init__.py Zeile 473 ) :

Code: Alles auswählen

############################################
# The base of all makepy generated classes
############################################
class DispatchBaseClass:
	def __init__(self, oobj=None):
		if oobj is None:
			oobj = pythoncom.new(self.CLSID)
		elif isinstance(oobj, DispatchBaseClass):
			try:
				oobj = oobj._oleobj_.QueryInterface(self.CLSID, pythoncom.IID_IDispatch) # Must be a valid COM instance
			except pythoncom.com_error as details:
				import winerror
				# Some stupid objects fail here, even tho it is _already_ IDispatch!!??
				# Eg, Lotus notes.
				# So just let it use the existing object if E_NOINTERFACE
				if details.hresult != winerror.E_NOINTERFACE:
					raise
				oobj = oobj._oleobj_
		self.__dict__["_oleobj_"] = oobj # so we dont call __setattr__
	# Provide a prettier name than the CLSID
	
		def __getattr__(self, attr):
		args=self._prop_map_get_.get(attr)
		if args is None:
			raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr)) [b] Kommentar : hier Zeile 473 ! [/b]
		return self._ApplyTypes_(*args)
		
Die Fehlermeldung bringt mich leider total nicht weiter, weil ich das Win32 Com Interface nicht ansatzweise kenne. Gefunden habe ich dazu noch :

Code: Alles auswählen


from win32com.client import DispatchBaseClass
class IAdditionalDescription(DispatchBaseClass):
	'IAdditonalDescription'
	CLSID = IID('{0B764757-2F83-4493-A185-E4AA29BD8EEF}')
	coclass_clsid = IID('{094FC1CC-96B5-43B9-84D0-4AED35E4678C}')

	def CloseWindows(self, windows=255):
		'method CloseWindows'
		return self._oleobj_.InvokeTypes(10, LCID, 1, (24, 0), ((3, 49),),windows
			)

	def OpenWindows(self, windows=255):
		'method OpenWindows'
		return self._oleobj_.InvokeTypes(9, LCID, 1, (24, 0), ((3, 49),),windows
			)

	_prop_map_get_ = {
		"Application": (1, 2, (9, 0), (), "Application", None),
		"DiagVariants": (3, 2, (9, 0), (), "DiagVariants", None),
		"FilePath": (5, 2, (8, 0), (), "FilePath", None),
		"Language": (7, 2, (8, 0), (), "Language", None),
		# Method 'MasterDescription' returns object of type 'IDiagDescription'
		"MasterDescription": (8, 2, (9, 0), (), "MasterDescription", '{8BDDB46D-7835-4FCE-9872-A208BE41ECC1}'),
		"Name": (0, 2, (8, 0), (), "Name", None),
		"Parent": (2, 2, (9, 0), (), "Parent", None),
		"Qualifier": (4, 2, (8, 0), (), "Qualifier", None),
		"Variant": (6, 2, (8, 0), (), "Variant", None),
	}


Fällt jemand etwas dazu ein ? Ich verwende Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32. CANoe_Interface.py ist schon ziemlich alt und den Programmierer gibt's nicht mehr, leider. Danke für jede gute Idee !
Gruß, Hlech65730
rogerb
User
Beiträge: 878
Registriert: Dienstag 26. November 2019, 23:24

@hlech65730,

Auf der Support Seite von Vector gibt es dazu wohl etwas. Hast du das schon probiert?
https://support.vector.com/kb?id=kb_art ... 0&spa=1#Q2
Benutzeravatar
__blackjack__
User
Beiträge: 13068
Registriert: Samstag 2. Juni 2018, 10:21
Wohnort: 127.0.0.1
Kontaktdaten:

In `SetSysVar()` wird `varType` gar nicht wirklich gebraucht weil der Code danach falsch ist. Es wird *immer* der erste ``if``-Zweig genommen, egal welchen Wert `varType` hat. Wer hat den Unsinn denn programmiert? Sowohl der Vergleich mit ``is`` ist falsch, als auch die ``or``-Verknüpfungen, die dafür sorgen, dass die erste Bedingung schon *immer* wahr ist. Die Methode liesse sich im Grunde auf folgenden Einzeiler verkürzen:

Code: Alles auswählen

    def SetSysVar(self, varNamespace, varName, varVal):
        """
        Description Sets the value of a SystemVariable object. 
        Parameters 
        1. varNamespace (string) The namespace where the system variable is stored.
        2. varName (string) The name of the system variable.
        3. varVal (varying) The value that is to be assigned to the system variable. 
        Return Values - 
        Example can_inst.SetSysVar('SecurityAccess', 'TesterPresentEnable', 1) 
        or:
        can_inst.SetSysVar('CodingParameters::CP_F198_Param', 'ByteArray', (48, 49, 50, 51, 52, 53))
        """
        self.Application.System.Namespaces(varNamespace).Variables(varName).Value = varVal
„All religions are the same: religion is basically guilt, with different holidays.” — Cathy Ladman
hlech65730
User
Beiträge: 9
Registriert: Samstag 10. Februar 2018, 19:28

Hallo __blackjack__,
ja klar, es kommt nach jedem if auch immer die gleiche Anweisung ! Ich habe mich durch die Fehlermeldung in die Irre führen lassen. Die Fehlermeldung ist jetzt weg, aber die CANoe variable wird noch nicht gesetzt. Aber das ist eine andere Geschichte , die ich selber lösen muß ! Danke erst mal !
Antworten