Python to Notes

What am I doing wrong here…

The code does fine till “print NView.Name”

But after that, its throwing the exception. Here is the complete output.

The database name is

XML

Settlement Invoices

Traceback (most recent call last):

AttributeError: ‘function’ object has no attribute ‘getItemValue’

File “”, line 1, in

File “/HYDRA/(commodities,ups)/NotesConnection.py”, line 24, in ConnectToNotes

AND YES… The view has documents

Here is the code, I am calling ConnectToNotes function from command line:

def NewNotesSession():

import win32com.client

NewSession=win32com.client.Dispatch("Lotus.NotesSession")

NewSession.Initialize()

return NewSession

def ConnectToNotes():

NewSession = NewNotesSession()

NotesDBase = NewSession.GetDatabase('DPUSMF001/DEV', 'enterprise2\\xml.nsf')

print 'The database name is '

print NotesDBase.Title

NView = NotesDBase.GetView('SettlementInvoices')

print NView.Name





NDoc = NView.getFirstDocument    

NItem = NDoc.getItemValue("Form")

print NotesItem(0)



pass

PS: Excuse my knowledge on Python, as this is my first Python code…

Subject: Python to Notes

NItem = NDoc.getItemValue(“Form”)>>print NotesItem(0)

print str(NDoc.getItemValue(“Form”)[0])

http://dominodev.blogspot.com/2009/07/lotus-notes-and-python.html

Subject: RE: Python to Notes

Thanks Tim, it worked… I guess it was a combination of syntax errors…

Here is the code that worked.

“”"

Id: $Id: NotesConnection.py,v 1.1 2009/12/21 14:41:04 pankaj.k.singh Exp $

Copyright: 2008 J.P. Morgan Chase & Co. Incorporated. All rights reserved.

Type: lib

Description: Lotus Notes Library

“”"

def NewNotesSession():

import win32com.client

NewSession=win32com.client.Dispatch("Lotus.NotesSession")

NewSession.Initialize('password')

return NewSession

def ConnectToNotes():

NewSession = NewNotesSession()

NotesDBase = NewSession.GetDatabase('DPUSMF001/JPMDEV', 'enterprise2\\xml.nsf')

print 'The database name : '

print NotesDBase.Title

if NotesDBase.IsOpen == True:

    print 'The database is open'

else:

    print 'The database is not open'

    

print NotesDBase.Title

NView = NotesDBase.GetView('SettlementInvoices')

print NView.Name



NotesVC = NView.AllEntries

print str(NotesVC.Count)



NotesVCENtry = NotesVC.getFirstEntry()

while not (NotesVCENtry is None):

    NotesVCDoc = NotesVCENtry.Document

    strForm = str(NotesVCDoc.getItemValue("form")[0])

    print strForm

    NotesVCENtry = NotesVC.getNextEntry(NotesVCENtry)





print "I cant do Python"



NDoc = NView.getFirstDocument()

print str(NDoc.getItemValue("form")[0])

Subject: RE: Python to Notes

Thanks Timothy… However, I am getting the same error msg

I am just wondering if I need to “import” something more?.. Also, the code is able to retrieve DB.Title. How is it able to do that when, no where in the code, I am supplying the ID password.

def NewNotesSession():

import win32com.client

NewSession=win32com.client.Dispatch("Lotus.NotesSession")

NewSession.Initialize('password')

return NewSession

def ConnectToNotes():

NewSession = NewNotesSession()

NotesDBase = NewSession.GetDatabase('DPUSMF001/DEV', 'enterprise2\\xml.nsf')

print 'The database name is '

print NotesDBase.Title

NView = NotesDBase.GetView('SettlementInvoices')

print NView.Name    



NDoc = NView.GetFirstDocument

print str(NDoc.getItemValue("Form")[0])



pass

Subject: RE: Python to Notes

As far as imports, you should only need to import the pythonwin for the com libraries (as you seem to be doing) via:

import win32com.client

Although I would declare this at the top of the code (for global access), not inside just one of the functions… although to be honest, I am forgetting the rules of scope here.

As far as authentication, using COM libraries requires access to the product’s native libraries (a.k.a. nnotes.dll has to be accessible).

If have Notes client up and running at the time you run your python script, and if your user id security setting has “Don’t prompt for a password from other Notes-based programs (reduces security)” - then this would explain the lack of the authentication prompt. You are effectively sharing your logged in state with your com program. This works the same when you are doing Notes C API and C++ API programming as well, or any other COM programming with Notes.

If you uncheck this or else close the Notes client, you should certainly get the password prompt each time you init a Notes session via COM…

I know you say the view has docs in it - but i’d make sure your program can see really the doc. Can you check the NDoc against null to make sure you have a valid handle?

if NDoc is None:

print “invalid doc handle”

And remember to use the appropriate whitespace/pretty print format - Python is sensitive to this.

Subject: RE: Python to Notes

Thanks for all your help Tim, as I said in my other post, things are working now. It had a few syntax errors.

Thanks also for shedding light on security. I would do some more research to test those.