[pywin32-bugs] [ pywin32-Bugs-3293883 ] InvokeType problem with python32
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: SourceForge.net <no...@so...> - 2011-05-02 17:06:39
|
Bugs item #3293883, was opened at 2011-04-27 19:06 Message generated for change (Comment added) made by You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=3293883&group_id=78018 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: com Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: millgner () Assigned to: Nobody/Anonymous (nobody) Summary: InvokeType problem with python32 Initial Comment: I want to control iTunes from python using pywin32 and just want ro add a track to a playlist it = win32com.client.Dispatch("iTunes.Application") pl = it.LibrarySource.Playlists.ItemByName("NewPL") if pl == None: pl = it.CreatePlaylist("NewPL"); track = it.LibraryPlaylist.Tracks[1] upl = win32com.client.CastTo(pl, "IITUserPlaylist") upl.AddTrack(track) This code works perfectly with python27 and pywin32-216.win32-py2.7.exe. But with python 3.2 and pywin32-216.1.win32-py3.2.exe i got the following error Traceback (most recent call last): File "D:\Users\fillg1\workspace\pyTest\src\event.py", line 34, in <module> upl.AddTrack(track) File "D:\Tools\Python32\lib\site-packages\win32com\gen_py\9E93C96F-CF0D-43F6-8BA8-B807A3370712x0x1x13\IITUserPlaylist.py", line 54, in AddTrack ret = self._oleobj_.InvokeTypes(1610874883, LCID, 1, (9, 0), ((16396, 1),),iTrackToAdd File "D:\Tools\Python32\lib\site-packages\win32com\client\__init__.py", line 462, in __getattr__ raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr)) AttributeError: '<win32com.gen_py.iTunes 1.13 Type Library.IITPlaylist instance at 0x44495728>' object has no attribute 'InvokeTypes' Any idea ? ---------------------------------------------------------------------- >Comment By: millgner () Date: 2011-05-02 19:06 Message: I have inserted a print(type(self), type(oobj)) as first line in __init__ result for 2.7 (<type 'instance'>, <type 'PyIDispatch'>) (<type 'instance'>, <type 'PyIDispatch'>) (<type 'instance'>, <type 'PyIDispatch'>) (<type 'instance'>, <type 'PyIDispatch'>) (<type 'instance'>, <type 'PyIDispatch'>) (<type 'instance'>, <type 'PyIDispatch'>) (<type 'instance'>, <type 'PyIDispatch'>) (<type 'instance'>, <type 'instance'>) (<type 'instance'>, <type 'PyIDispatch'>) and for 3.2 <class 'win32com.gen_py.9E93C96F-CF0D-43F6-8BA8-B807A3370712x0x1x13.IiTunes.IiTunes'> <class 'PyIDispatch'> <class 'win32com.gen_py.9E93C96F-CF0D-43F6-8BA8-B807A3370712x0x1x13.IITSource.IITSource'> <class 'PyIDispatch'> <class 'win32com.gen_py.9E93C96F-CF0D-43F6-8BA8-B807A3370712x0x1x13.IITPlaylistCollection.IITPlaylistCollection'> <class 'PyIDispatch'> <class 'win32com.gen_py.9E93C96F-CF0D-43F6-8BA8-B807A3370712x0x1x13.IITPlaylist.IITPlaylist'> <class 'PyIDispatch'> <class 'win32com.gen_py.9E93C96F-CF0D-43F6-8BA8-B807A3370712x0x1x13.IITLibraryPlaylist.IITLibraryPlaylist'> <class 'PyIDispatch'> <class 'win32com.gen_py.9E93C96F-CF0D-43F6-8BA8-B807A3370712x0x1x13.IITTrackCollection.IITTrackCollection'> <class 'PyIDispatch'> <class 'win32com.gen_py.9E93C96F-CF0D-43F6-8BA8-B807A3370712x0x1x13.IITTrack.IITTrack'> <class 'PyIDispatch'> <class 'win32com.gen_py.9E93C96F-CF0D-43F6-8BA8-B807A3370712x0x1x13.IITUserPlaylist.IITUserPlaylist'> <class 'win32com.gen_py.9E93C96F-CF0D-43F6-8BA8-B807A3370712x0x1x13.IITPlaylist.IITPlaylist'> Traceback (most recent call last): File "D:\Users\fillg1\workspace\pyTest\src\test.py", line 12, in <module> upl.AddTrack(track) File "D:\Tools\Python32\lib\site-packages\win32com\gen_py\9E93C96F-CF0D-43F6-8BA8-B807A3370712x0x1x13\IITUserPlaylist.py", line 54, in AddTrack ret = self._oleobj_.InvokeTypes(1610874883, LCID, 1, (9, 0), ((16396, 1),),iTrackToAdd File "D:\Tools\Python32\lib\site-packages\win32com\client\__init__.py", line 464, in __getattr__ raise AttributeError("'%s' object has no attribute '%s'" % (repr(self), attr)) AttributeError: '<win32com.gen_py.iTunes 1.13 Type Library.IITPlaylist instance at 0x42196656>' object has no attribute 'InvokeTypes' And now comes the interesszting point if I delete the generated dispatch classes it works excatly once. So may be a bug in genpy ? I will attach the generated files ---------------------------------------------------------------------- Comment By: millgner () Date: 2011-05-02 16:30 Message: OK, I will try this ---------------------------------------------------------------------- Comment By: Mark Hammond (mhammond) Date: 2011-05-02 14:16 Message: I was talking about the DispatchBaseClass in win32com.client - but the makepy generated dispatch classes all derive from this. ---------------------------------------------------------------------- Comment By: millgner () Date: 2011-05-02 09:44 Message: >For some reason though things are going wrong. It would be great if you >could sprinkle some print() statements in the __init__ function so we can >try and see what it going wrong. Sorry I did not get this which __init__ function do you mean ? The code generated by genpy /makepy ? or wincom32.client ? ---------------------------------------------------------------------- Comment By: Mark Hammond (mhammond) Date: 2011-04-28 02:39 Message: I can't reproduce this with COM objects other than ITunes. What should happen is that the __init__ function in DispatchBaseClass in win32com\client\__init__.py is called with your "pl" object. Then the line: oobj = oobj._oleobj_.QueryInterface(self.CLSID, pythoncom.IID_IDispatch) # Must be a valid COM instance should be called, which should return a low-level COM object (ie, one that prints as "<PyIDispatch at 0x02B9F250 with obj at 0x0330EA18>" - this is the object with the InvokeTypes method. This object should then be stored in the object's _oleobj_ attribute. Then, as shown in the traceback, when calling AddTrack it does: self._oleobj_.InvokeTypes() - where self._oleobj_ should be the object which was returned above by QueryInterface. For some reason though things are going wrong. It would be great if you could sprinkle some print() statements in the __init__ function so we can try and see what it going wrong. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=3293883&group_id=78018 |