尝试使用 win32com.client.Dispatch() 使用 ProgID "QBXMLRP2Lib.RequestProcessor2" 连接到 Quickbooks 时出现错误

I am getting an error when trying to connect to Quickbooks using win32com.client.Dispatch() using ProgID "QBXMLRP2Lib.RequestProcessor2"

根据我能找到的有限文档,我编写了以下代码:

import win32com.client
import xml.etree.ElementTree as Et

newSession = win32com.client.Dispatch("QBXMLRP2Lib.RequestProcessor2") 

但我收到以下错误:

>Traceback (most recent call last):
>  File "C:\Users\Clear\AppData\Local\Programs\Python\Python37\lib\site->packages\win32com\client\dynamic.py", line 89, in _GetGoodDispatch
>    IDispatch = pythoncom.connect(IDispatch)
>pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
>
>During handling of the above exception, another exception occurred:
>
>Traceback (most recent call last):
>  File >"C:\Users\Clear\AppData\Local\Programs\Python\Python37\learn_win32com.py", >line 4, in <module>
>    newSession = win32com.client.Dispatch("QBXMLRP2Lib.RequestProcessor2")
>  File "C:\Users\Clear\AppData\Local\Programs\Python\Python37\lib\site->packages\win32com\client\__init__.py", line 95, in Dispatch
>    dispatch, userName = >dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
>  File "C:\Users\Clear\AppData\Local\Programs\Python\Python37\lib\site->packages\win32com\client\dynamic.py", line 114, in >_GetGoodDispatchAndUserName
>    return (_GetGoodDispatch(IDispatch, clsctx), userName)
>  File "C:\Users\Clear\AppData\Local\Programs\Python\Python37\lib\site->packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
>    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, >pythoncom.IID_IDispatch)
>pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)

我是 COM 和 win32com 的新手,还处于编程的初级阶段。

你能帮我理解我做错了什么吗?

现在正在运行。

我的问题是我试图分别对每个步骤进行故障排除,所以我尝试 运行 只是 win32com.client.Dispatch:

sessionManager = win32com.client.Dispatch("QBXMLRP2.RequestProcessor")

创建一个包含 win32com.client.Dispatch + OpenConnection + BeginSession 的 class 效果很好:

sessionManager = win32com.client.Dispatch("QBXMLRP2.RequestProcessor")
sessionManager.OpenConnection('', "My test app")
ticket = sessionManager.BeginSession('', 0)
return (sessionManager,ticket)

我希望这对在线下的人有所帮助。