我希望在文件上传到webdav服务器时获取文件传输进度信息。我尝试将WithEvents用于Session对象的set处理程序,但它会因错误而停止:
C:\Miniconda3\python.exe E:/backup_1c/winscp.py
Traceback (most recent call last):
File "E:/backup_1c/winscp.py", line 16, in <module>
wcpSession.open(winscp_session_option)
File "<COMObject WinSCP.Session>", line 2, in open
pywintypes.com_error: (-2147352567, 'Error.', (0, 'mscorlib', 'Member group not found. (Exception HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))', None, 0, -2147352573), None)
Process finished with exit code 1
脚本代码是:
# -*- coding: utf-8
import win32com.client as win32
class WinScp_ISessionEvents:
def OnFileTransferProgress(self, e):
print(e.FileProgress)
if __name__ == "__main__":
wcpSession = win32.dynamic.Dispatch('WinSCP.Session')
winscp_session_option = win32.dynamic.Dispatch('WinSCP.SessionOptions')
winscp_session_option.Protocol = 3
winscp_session_option.HostName = "webdav.yandex.ru/"
winscp_session_option.UserName = "user"
winscp_session_option.Password = "password"
win32.WithEvents(wcpSession, WinScp_ISessionEvents)
wcpSession.open(winscp_session_option)
wcpSession.PutFiles('E:\Exchange\File.xls', '/File.xls')
根据错误消息我在WinScp_ISessionEvents类中有错误的函数名称,我尝试了不同的名称,如FileTransferProgress,Session_FileTransferProgress,wcpSession_FileTransferProgress,wcpSession_OnFileTransferProgress等等。
答案 0 :(得分:0)
callstack在wcpSession.open
显示问题,而不是win32.WithEvents
。
问题不在于.Open
,而不是.open
?