On Feb 6, 2008 1:53 PM, Thomas Heller <[EMAIL PROTECTED]> wrote:
> I'll fix this in Python SVN asap; fortunately it seems that it is possible
> to monkeypatch comtypes' COMError to add a workaround for the bug.
> If you add the following code snippet to comtypes\__init__.py you can try
> it out; I have already committed this to comtypes svn and added a test.
> Please try it out if it works for you.
>
> Thanks,
> Thomas
>
> <snippet>
> try:
> COMError()
> except TypeError:
> pass
> else:
> # Python 2.5 and 2.5.1 have a bug in the COMError implementation:
> # The type has no __init__ method, and no hresult, text, and
> # details instance vars. Work around this bug by monkeypatching
> # COMError.
> def monkeypatch_COMError():
> def __init__(self, hresult, text, details):
> self.hresult = hresult
> self.text = text
> self.details = details
> super(COMError, self).__init__(hresult, text, details)
> COMError.__init__ = __init__
> def __repr__(self):
> return "%s(%r, %r, %r)" % (self.__class__.__name__, self.hresult,
> self.text, self.details)
> COMError.__repr__ = __repr__
> monkeypatch_COMError()
> del monkeypatch_COMError
> </snippet>
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> comtypes-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/comtypes-users
>
This works perfectly. Here is a sample Idle session:
>>> import comtypes.client
>>> from comtypes import COMError
>>> lns = comtypes.client.CreateObject('Lotus.NotesSession')
>>> try:
lns.Initialize('abcd')
except COMError, e:
pass
>>> e
COMError(-2147217504, None, (u'Notes error: Wrong Password. (Passwords
are case sensitive - be sure to use correct upper and lower case.)',
u'NotesSession', None, 0, None))
>>> e.details
(u'Notes error: Wrong Password. (Passwords are case sensitive - be
sure to use correct upper and lower case.)', u'NotesSession', None, 0,
None)
>>> e.message
''
>>> e.hresult
-2147217504
Thanks four your valuable time
- Suraj
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
comtypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/comtypes-users