win32api文件路径
我有一个使用Win32API重新计算Excel文件的脚本。它可以无错误。
当我尝试通过pywinrm远程运行相同的脚本时,我会发现一个错误:
错误:com_error:((-2147352567,'异常发生。 'xlmain11.chm',0,-2146827284),无)
有什么问题?
import winrm
host = 'myhost'
domain = 'mydomain'
user = 'myuser'
password = 'mypassword'
session = winrm.Session(host, auth=('{}@{}'.format(user,domain), password), transport='ntlm')
result = session.run_ps('python script.py')
远程计算机上的script.py
import win32com.client
xlapp = win32com.client.DispatchEx("Excel.Application")
xlapp.Visible = True
path = "C:\\Users\\MyUser\\Desktop\\excel\\test_file.xlsx"
wb = xlapp.Workbooks.open(path)
文件在此路径上存在。它可以通过open('Path',rb)
读取。如果我在远程计算机上运行相同的代码(手动无需WinRM),则没有问题。
I have a script that re-calculates an Excel file using win32api. It works without errors.
When I try to run the same script remotely through pywinrm, I get an error:
Error: com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', "Sorry, we couldn't find test1.xlsm. Is it possible it was moved, renamed or deleted?", 'xlmain11.chm', 0, -2146827284), None)
What can be the problem?
import winrm
host = 'myhost'
domain = 'mydomain'
user = 'myuser'
password = 'mypassword'
session = winrm.Session(host, auth=('{}@{}'.format(user,domain), password), transport='ntlm')
result = session.run_ps('python script.py')
script.py on remote machine
import win32com.client
xlapp = win32com.client.DispatchEx("Excel.Application")
xlapp.Visible = True
path = "C:\\Users\\MyUser\\Desktop\\excel\\test_file.xlsx"
wb = xlapp.Workbooks.open(path)
The file exists on this path. It can be read via open('path', rb)
. If I run the same code on a remote machine (without winrm, manually), there is no problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论