我想在python中创建一个脚本,从Lotus Notes 8.5中读取邮件,然后在jira中为每个电子邮件创建一个问题,但是当我尝试从Lotus读取邮件时,它会返回此错误:
Traceback (most recent call last):
File "from_Lotus_TO_Jira.py", line 46, in <module>
main()
File "from_Lotus_TO_Jira.py", line 39, in main
folder = notesDatabase.GetView('$Inbox')
File "C:\Python27\lib\site-packages\win32com\gen_py\29131520-2EED-1069-BF5D-00
DD011186B7x0x1x2.py", line 1849, in GetView
ret = self._oleobj_.InvokeTypes(1610743866, LCID, 1, (9, 0), ((8, 1),),pName
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'NotesDatabase',
u'Database server_name!!C:\\Users\\MYNAME\\AppData\\Local\\Lotus\\Notes\\Data\\ma
il202\\myname.nsf has not been opened yet', None, 0, -2147217441), None)
这是我的.py文件
import win32com.client
import pywintypes
import getpass
def main():
# Get credentials
mailServer = 'server_name'
mailPath = 'C:\Users\MYNAME\AppData\Local\Lotus\Notes\Data\mail202\myname.nsf'
mailPassword = ''
# Connect
notesSession = win32com.client.Dispatch('Lotus.NotesSession')
notesSession.Initialize(mailPassword)
notesDatabase = notesSession.GetDatabase(mailServer, mailPath)
# Get a list of folders
folder = notesDatabase.GetView('$Inbox')
document = folder.GetFirstDocument()
if __name__ == "__main__":
main()
答案 0 :(得分:3)
查看http://www-01.ibm.com/support/docview.wss?uid=swg21308538
完整的文件路径(例如&#34; C:\ notes \ data \ r_apps \ haha.nsf&#34;)可能 在访问工作站上的本地数据库时可以选择使用。如果 但是,您指定了服务器名称,或者代码是否在a上运行 在服务器上,必须使用相对于Notes数据目录的路径 (&#34; r_apps \ haha.nsf&#34)。
我建议(a)不指定服务器或(b)仅提供相对路径,即mailPath = r'mail202\myname.nsf'
。
答案 1 :(得分:2)
您正在使用Notes COM类。打开当前用户的邮件数据库有一个很好的快捷方式调用。 NotesSession class包含GetDbDirectory method,它返回NotesDbDirectory对象,而NotesDbDirectory class包含OpenMailDatabase method。
我不是一个Python人,所以我不能保证确切的语法,但它应该是这样的:
notesSession.Initialize(mailPassword)
notesDbDirectory = notesSession.GetDbDirectory('')
notesDatabase = NotesDbDirectory.GetMailDatabase()
请注意,GetDbDirectory的参数可以是空字符串或Domino服务器的名称。它应该没有任何区别,因为GetMailDatabase方法遵循与NotesDatabase.OpenMail method相同的过程(不通过COM接口公开,因此它不可用于Python)。即,它查看当前用户的Notes客户端配置,以找到用户邮件数据库的基于服务器或本地副本。
另请注意,如果此代码旨在在一台计算机上运行,但为一台Domino服务器上的许多用户处理邮件,则无法使用GetMailDatabase方法。在这种情况下,使用@ Hugh-Bothwell的答案中的相对路径是正确的,尽管我强烈建议通过调用GetDatabase()
和GetView()
之间的notesDatabase.IsOpen()来添加一些防御性编程。 {1}}。