python - 尝试使用 Pywin32 连接到 SAPGUI 时出错
问题描述
我正在使用此功能连接到 SAPGUI:
def sap_connect(local_sap_box):
SapGuiAuto = win32com.client.GetObject('SAPGUI')
if not type(SapGuiAuto) == win32com.client.CDispatch:
return
application = SapGuiAuto.GetScriptingEngine
if not type(application) == win32com.client.CDispatch:
SapGuiAuto = None
return
connection = application.OpenConnection(local_sap_box,True)
if not type(connection) == win32com.client.CDispatch:
application = None
SapGuiAuto = None
return
session = connection.Children(0)
sap_box = session.findById('wnd[0]/sbar/pane[1]').text
sap_box = sap_box[0:3]
sap_sbar = session.findById('wnd[0]/sbar').text
sap_user = sap_sbar[17:23]
print('User ' + sap_user + ' logged into ' + sap_box)
if not type(session) == win32com.client.CDispatch:
connection = None
application = None
SapGuiAuto = None
return
return session
从今天开始,我收到一个 'com_error: (-2147221020, 'Invalid syntax', None, None)' 错误。
这是完整的错误消息:
---------------------------------------------------------------------------
com_error Traceback (most recent call last)
<ipython-input-3-1c5ab2335269> in <module>
9 for order_group in order_groups:
10 for sap_box, currency_settings in order_groups[order_group].items():
---> 11 sap_session = sap_connect(sap_box)
12 sap_RPX0(sap_session, currency_settings)
13 kob1 = sap_KOB1(sap_session, order_group, '07/01/2021', '06/30/2022', 'ID_KOB1_ALL')
<ipython-input-2-9c51187610f0> in sap_connect(local_sap_box)
1 def sap_connect(local_sap_box):
----> 2 SapGuiAuto = win32com.client.GetObject('SAPGUI')
3 if not type(SapGuiAuto) == win32com.client.CDispatch:
4 return
5 application = SapGuiAuto.GetScriptingEngine
~\Anaconda3\lib\site-packages\win32com\client\__init__.py in GetObject(Pathname, Class, clsctx)
70 return GetActiveObject(Class, clsctx)
71 else:
---> 72 return Moniker(Pathname, clsctx)
73
74 def GetActiveObject(Class, clsctx = pythoncom.CLSCTX_ALL):
~\Anaconda3\lib\site-packages\win32com\client\__init__.py in Moniker(Pathname, clsctx)
85 Python friendly version of GetObject's moniker functionality.
86 """
---> 87 moniker, i, bindCtx = pythoncom.MkParseDisplayName(Pathname)
88 dispatch = moniker.BindToObject(bindCtx, None, pythoncom.IID_IDispatch)
89 return __WrapDispatch(dispatch, Pathname, clsctx=clsctx)
com_error: (-2147221020, 'Invalid syntax', None, None)
我正在使用 SSO,SAPGUI Logon Pad 是 760。这里出了什么问题?
解决方案
推荐阅读
- reactjs - React - Redux:使用 Thunk 进行异步调用
- razor - 更改元素的类
- python - 无法使用 numpy 的输出索引 igraph vs
- scala - 查找两个日期之间的日期
- java - Jade4J:没有这样的文件或目录
- tomcat - 在tomcat9上重定向
- ios - 应用加入 agora.io 频道时,AVAudioPlayer 自动停止
- git - 如何在保留文件的同时将已提交的文件添加到 .gitignore?
- java - 为我的类扩展引发了 InstantiationException
- docker - 如何更改默认 docker 子网 - Docker for Windows、Visual Studio 2017?