[python-win32] Python COM server throws 'module' object has no attribute 'VARIANT'

Mark Hammond skippy.hammond at gmail.com
Mon Aug 6 03:41:55 CEST 2012


I don't quite understand this code.  The server is using win32com (ie, 
not comtypes), but the client code seems to be using comtypes rather 
than win32com (but it's hard to tell as the client code is missing the 
imports etc).  But at face value it appears one of the machines might 
have an older version of comtypes installed.

Mark

On 5/08/2012 11:13 PM, Paul Hemans wrote:
> Can someone tell me what is going wrong. The following works on one
> machine but not on another.
>
> Here is a COM server implemented in Python:
>
> |from  win32com.server.exceptionimport  COMException
>
> import  pythoncom
>
> import  sys
>
> import  os
>
> from  string  import  Template
>
> import  logging
>
> import  logging.config
>
>
> class  Connector:
>
>      _reg_clsctx_=  pythoncom.CLSCTX_LOCAL_SERVER
>
>      _reg_clsid_=  "{0CE25AEB-1AFA-4DA7-97BD-F93CDBFB376C}"
>
>      _reg_desc_=  "Python Test COM Server"
>
>      _reg_progid_=  "Compy.Connect"
>
>      _public_methods_=  ['Process',  'Status']
>
>      _public_attrs_=  []
>
>      _readonly_attrs_=  []
>
>
>      def  Process(self,  what):
>
>          pass
>
>
>      def  Status(self):
>
>          return  Template("""
>
>          Current Directory: $dir
>          Installed: $script
>          PythonPATH: $pyPath
>          """).substitute(dir=  os.getcwd(),
>
>                          script=  os.path.abspath(__file__),
>
>                          pyPath=  sys.path)
>
>
> if  __name__==  '__main__':
>
>      import  win32com.server.register
>
>      win32com.server.register.UseCommandLine(Connector)
>
> |
>
> It registers ok. When it is run it causes the following to occur on the
> production machine but NOT on the development box:
>
> |>>>  cc=  CreateObject("Compy.Connect")
>
>>>>  cc.Status()
>
> Traceback  (most recent calllast):
>
>    File  "<stdin>",  line1,  in  <module>
>
>    File  "C:\Python26\lib\site-packages\comtypes\client\dynamic.py",  line42,  in  _
>
> _call__
>      return  self._obj._comobj.Invoke(self._id,  *args)
>
>    File  "C:\Python26\lib\site-packages\comtypes\automation.py",  line717,  in  Invo
>
> ke
> raise  COMError(hresult,  text,  details)
>
> _ctypes.COMError:  (-2147352567,  'Exception occurred.',  (u"Unexpected Python Erro
>
> r: AttributeError: 'module' object has no attribute 'VARIANT'\n",  u'Python COM S
>
> erver Internal Error',  None,  0L,  -2147467259))
>
>>>>
>
> |
>
> I have installed comtypes 0.6.2. Running Python 2.6.6
>
>
>
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>



More information about the python-win32 mailing list