在python中使用win32com.client时无法打开ID文件

问题描述:

我有一个使用win32com.client从Python连接到Lotus Notes的问题。在python中使用win32com.client时无法打开ID文件

我使用下面的代码:

import win32com.client 
import csv # imports the csv module 
import sys # imports the sys module 
import re 

notesServer = "AALMBX01/Server/..." 
notesPass = "PASS" 

#Connect to notes database on server 
notesSession = win32com.client.Dispatch('Lotus.NotesSession') 
notesSession.Initialize(notesPass) 

db_name = 'mail\iizs.nsf' 
db = notesSession.getDatabase(notesServer, db_name) 
view = db.GetView("($All)") 
doc = view.getFirstDocument() 

而且我得到以下错误:

(-2147352567, 'Exception occurred.', (0, u'NotesSession', u'Notes error: Wrong Password. (Passwords are case sensitive - be sure to use correct upper and lower case.)'

还试图离开密码留空并禁用“为LN应用要求密码”的界面。使用空白密码,我收到以下错误消息:

(-2147352567, 'Exception occurred.', (0, u'NotesDatabase', u'Database AALMBX01/Server/...!!mail\iizs.nsf has not been opened yet'

我曾尝试以下:

  1. 使用lnlib和get_session功能。
  2. 检查notus.ini文件是否到位(在我的情况下是C:\ Users \ iizs \ NotesData),并包含对userid的引用(尝试将用户ID文件的完整路径添加到C:\ Users \ iizs \ Notes数据\数据)。
  3. 添加值HKEY_CURRENT_USER \ SOFTWARE \莲花\注释(可选的版本)\的NotesIniPath
  4. 加入含有notes.ini文件的文件夹(C:\ Users \用户iizs \ Notes数据)和user.id文件(C: \ Users \ iizs \ NotesData \ data)添加到PATH环境变量中。

错误仍然是一样的。试图将user.id复制到系统文件夹之一(system32) - 也没有帮助。

有什么建议吗?

import win32com.client 
import pywintypes 
from win32com.client import Dispatch 
from win32com.client import constants 
notesSession = Dispatch('Lotus.NotesSession') 
dir(constants) 
dir(notesSession) 
Password = 'S3cretP455w0rd' 
Server = 'yourserver/yourapp' # yourserver = '' if local 
scPath = 'view.nsf' 
notesSession.Initialize(Password) 

HTH !!

此外,一个“疑难杂症”这事对我来说是网络驱动器 - 如果你的NOTES.INI文件中包含的网络路径,尝试删除并在Python代码添加它:

[code] 
import os 
os.system('net use w: /delete') 
os.system('net use w: \\\\apps\\NotesFolder') 
[/code] 
+0

谢谢你的评论!现在我收到一条错误消息:“(-2147352567,'发生了异常',(0,u'NotesSession',u'Notes错误:密码错误(密码区分大小写 - 请务必使用正确的大写和小写。'',None,0,-2147217504),None)“。我当然使用正确的密码,请问可能会有什么问题? –

+0

此外,当我试图离开密码空白,它连接正常,但然后我得到一个错误在GetView()说:“数据库...还没有打开过。”有什么建议? –

+0

我没有打错误之前,但要确保你的Python脚本在单引号(例如'password')中有你的密码,而不是双引号(例如“password”),因为有些语言试图'解释'字符串。我不知道这种语言是否属实,但它是其他地方的障碍...... – neophytte