我正在尝试使用 Python 登录 SAPGUI,以便创建一个脚本来自动运行事务,但我遇到了问题。每当我尝试登录时,我都会收到<class 'pywintypes.com_error'>
错误。我不确定为什么会出现此错误。这是我第一次尝试导航到 SAP GUI,因此我不确定是否缺少建立成功登录的重要行。
我们以前使用过 VBA,但我的同事表示有兴趣将我们的自动化脚本从 Excel 迁移到 Python,而且由于我在 Python 方面经验最丰富,所以我的任务是让它正常工作。
# Importing the Libraries
import win32com.client
import sys
import subprocess
import time
# This function will Login to SAP from the SAP Logon window
def saplogin():
try:
path = r"C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe"
subprocess.Popen(path)
time.sleep(10)
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.Children(0)
if not type(connection) == win32com.client.CDispatch:
application = None
SapGuiAuto = None
return
session = connection.Children(1)
if not type(session) == win32com.client.CDispatch:
connection = None
application = None
SapGuiAuto = None
return
session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "USER"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "PASS"
session.findById("wnd[0]").sendVKey(0)
except:
print(sys.exc_info()[0])
finally:
session = None
connection = None
application = None
SapGuiAuto = None
saplogin()
回答您有关登录自动化的问题,它是这样完成的:
import subprocess
subprocess.check_call(['C:\Program Files (x86)\SAP\FrontEnd\SAPgui\\sapshcut.exe', '-system=DCG210', '-client=100', '-user=USERNAME', '-pw=PASSWORD'])
where DG210
- SAP 系统的名称已在 SAPGui 中设置
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)