[python-win32] Re: 'NoneType' object is not callable

apocalypznow apocalypznow at yahoo.com
Tue Sep 7 07:02:58 CEST 2004


Thanks for your help Mark.
I tried:
     mfcserver = mod.Application(mfcserver)
but I get this error:
     AttributeError: 'NoneType' object has no attribute 'Application'

But when I tried to mfcserver._FlagAsMethod('SendMessage1'), and upon 
execution of mfcserver.SendMessage1("hi"), IT WORKED!

You say that the automation server is responding to the request as a 
*property*.  However, here is the dispatch map:
BEGIN_DISPATCH_MAP(CTestmfcserverDlgAutoProxy, CCmdTarget)
	//{{AFX_DISPATCH_MAP(CTestmfcserverDlgAutoProxy)
	DISP_FUNCTION(CTestmfcserverDlgAutoProxy, "SendMessage1", SendMessage1, 
VT_VARIANT, VTS_VARIANT)
	//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()

The makepy generated file shows it to be a method:
class ITestmfcserver(DispatchBaseClass):
	CLSID = IID('{3EC90822-8332-4CEB-834B-36E453010E46}')
	coclass_clsid = IID('{7B898434-6DEE-499F-9820-6D337EF00D9C}')

	def SendMessage1(self, param1=defaultNamedNotOptArg):
		return self._ApplyTypes_(1, 1, (12, 0), ((12, 0),), 'SendMessage1', 
None,param1)

	_prop_map_get_ = {
	}
	_prop_map_put_ = {
	}


This is very puzzling... I've been through the VC++ automation wizard at 
least 3 times, each time I am sure it is executing as a method (for 
example, I put in an AfxMessageBox() that executes in the body of the 
method).  A VB client likewise has no problem with it.  Can you give me 
some clue as to what might be happening?

>>I always get this error when calling a function on the automation
>>server: 'NoneType' object is not callable
>>Then the python program stops executing.  In the code below,
>>mfcserver.SendMessage1() gives the error, and the print
>>"Finished" line
>>never executes.
> 
> 
> Your COM server is reponding to a request for a *property* named
> "SendMessage1", and returning None.  Python it then attempting to call it.
> You should raise DIS_E_MEMBERNOTFOUND when it is requested as a property.
> 
> You can worm around that using:
> ob._FlagAsMethod("SendMessage1") before trying to make the call.
> 
> 
>>It looks as though the dispatch is happening dynamically.  The error
>>happens even if gencache is not used.
> 
> 
> That means your object is not responding to GetTypeInfo() - so python has no
> clue what type lib info to use.  You should be able to worm around that by:
> 
> mod = gencache.EnsureModule('{6CAC46EE-C71C-475C-B372-2E988DA78678x0x1x0}',
> 0, 1, 0)
> mfcserver = win32com.client.Dispatch("Testmfcserver.Application")
> mfcserver = mod.Application(mfcserver)
> mfcserver.SendMessage1("Hello server.")
> 
> ie, if that works, there should be no need to use _FlagAsMethod (indeed, it
> will fail)
> 
> Mark



More information about the Python-win32 mailing list