FAQ
Hello everyone. I have to get data from Lotus Notes and i curious is it
possible doing it with Python. I heard that Lotus Notes using COM, so
the Python does so maybe it can be done? Anyone have any experiences
doing that?
Ane help will by apreciated
Gregor

Search Discussions

  • Graham Fawcett at Nov 2, 2005 at 2:24 pm

    Grzegorz Slusarek wrote:
    Hello everyone. I have to get data from Lotus Notes and i curious is it
    possible doing it with Python. I heard that Lotus Notes using COM, so
    the Python does so maybe it can be done? Anyone have any experiences
    doing that?
    Ane help will by apreciated
    Yes, it's pretty simple. Quick example:

    from win32com.client import Dispatch
    session = Dispatch('Lotus.NotesSession')
    session.Initialize(MY_NOTES_PASSWORD)

    db = session.getDatabase(SERVER_NAME, DB_NAME)
    ...

    The LotusScript reference guide is almost completely applicable to
    Notes via COM.

    It can be useful to define some helper functions to make working with
    Notes a bit easier. For example, this is the (very clunky) way to
    iterate all documents in a Notes database, without helper code:

    view = db.getView('Important Docs')
    doc = db.getFirstDocument()
    while doc:
    do_something_with(doc)
    doc = view.getNextDocument(doc)

    You probably recognize the pattern from any LotusScript you've written.
    (It sure is easy to forget that last line...)

    But Python gives you far better control structures, like generators.
    It's worthwhile to define a few helper functions like this, in a common
    module:

    def iterateDocuments(docs):
    doc = docs.getFirstDocument()
    while doc:
    yield doc
    doc = docs.getNextDocument(doc)

    Then you can write much cleaner code, like this:

    for doc in iterateDocuments(view):
    do_something_with(doc)

    Similarly you can write iterator functions for traversing databases,
    ACL entries, etc.

    I also find these two defnitions useful:

    def get(doc, attr):
    return doc.getItemValue(attr)

    def get1(doc, attr):
    return get(doc, attr)[0]

    because it's a lot easier to write:

    user_name = get1(user_doc, 'FullName')

    than:

    user_name = user_doc.getItemValue('FullName')[0]

    Note that the attribute-access style that LotusScript allows, e.g.
    "user_doc.FullName(0)" does not work in Python/COM, hence you'll need
    getItemValue(), replaceItemValue(), etc.. You could write a wrapper for
    the NotesDocument class that would give you attributes like this.
    Personally, I find that to be more trouble than it's worth, but your
    needs be very different.

    Last warning: once you've tried using Python and COM, you'll scream
    whenever you have to write LotusScript, and you'll wish like crazy that
    Notes/Domino supported Python as a native scripting language. :-)
    Jython kind of works, but I never got it happily running for
    server-side code, alas.

    Graham
  • Grzegorz Ślusarek at Nov 3, 2005 at 7:45 am
    thank you Graham
    Now I know how to get it thru
    And i have last question is it possible send mail from Lotus via
    Python/COM?
    Once Again Thanks
  • Marco Aschwanden at Nov 4, 2005 at 11:01 am
    The second line of your code is already a show stopper in my case:

    from win32com.client import Dispatch
    session = Dispatch('Lotus.NotesSession')
    session.Initialize('my_secret_passwort')

    When started, ends:

    File
    "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
    line 310, in RunScript
    exec codeObject in __main__.__dict__
    File "C:\temp\notes_init.py", line 3, in ?
    session.Initialize('my_secret_passwort')
    File "c:\Python24\lib\site-packages\win32com\client\dynamic.py", line
    489, in __getattr__
    raise AttributeError, "%s.%s" % (self._username_, attr)
    AttributeError: Lotus.NotesSession.Initialize

    It worked before though with Version 5.x of Notes. In Notes Version 6.X
    they introduced the session.Initialize() - that was the point, when I
    couldn't create an instance anymore. I found no hint on the net... Do you
    have any idea what is going wrong here?

    Regards,
    Marco
  • Graham Fawcett at Nov 4, 2005 at 4:58 pm

    Marco Aschwanden wrote:
    The second line of your code is already a show stopper in my case:

    from win32com.client import Dispatch
    session = Dispatch('Lotus.NotesSession')
    session.Initialize('my_secret_passwort')

    When started, ends:
    [snip]
    AttributeError: Lotus.NotesSession.Initialize

    It worked before though with Version 5.x of Notes. In Notes Version 6.X
    they introduced the session.Initialize() - that was the point, when I
    couldn't create an instance anymore. I found no hint on the net... Do you
    have any idea what is going wrong here?
    I'm using 6.x here, so that's not the problem.

    Is there any chance you have an old gen_py file in your path? E.g.,
    does re-running the PythonWin "makepy" utility again make a difference?
    Just a thought, but something might be "hard-coded" to your earlier 5.x
    COM interface, and gen_py would be a likely suspect.

    Also, If you have another language that you can use to do COM, e.g.
    Visual Basic (in any of the MS Office apps, or in Visual Studio),
    verify that you can create a Lotus.NotesSession using those
    environments as well. It might be a lower-level (non-Python-related)
    problem.

    Graham
  • Thakadu at Nov 4, 2005 at 8:03 pm
    I have had success with jython using the notes.jar classes, for
    example:

    import lotus.domino
    import java.io
    import java.net
    import java.lang
    import java.util

    lotus.notes.NotesThread.sinitThread()
    S = lotus.notes.Session.newInstance();
    db=S.getDatabase("server/domain","domlog.nsf")
    agent=db.getAgent("DeleteOldDocs")
    for x in range(50):
    print x
    result=agent.runOnServer()
    print "res %d" % result
  • Bisj at Nov 13, 2005 at 12:54 pm

    I would like to interact with Lotus Notes. I wrote following:
    from win32com.client.dynamic import Dispatch
    ln=Dispatch('Lotus.Notessession')
    then, following exception come out:
    Traceback (most recent call last):
    File "<interactive input>", line 1, in ?
    File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
    98, in Dispatch
    IDispatch, userName =
    _GetGoodDispatchAndUserName(IDispatch,userName,clsctx)
    File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
    91, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
    File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
    79, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
    pythoncom.IID_IDispatch)
    com_error: (-2147221005, 'Invalid class string', None, None)

    I searched google, above code lines should be ok, but really don't know
    how the exception come out. Could this be resolved? Thanks.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedNov 2, '05 at 10:38a
activeNov 13, '05 at 12:54p
posts7
users5
websitepython.org

People

Translate

site design / logo © 2022 Grokbase