【发布时间】:2021-11-24 11:40:06
【问题描述】:
我有下面的简单代码尝试连接一台 Windows 机器,我可以使用 Windows 的 rdp(远程桌面)连接该机器
但是在 python 中使用 pywinrm 我得到了以下错误
requests.exceptions.ConnectionError: HTTPConnectionPool(host='10.XX.XX.XX', port=5986): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001F44F92A6D0>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))
我有密码
import winrm
session = winrm.Session('10.XX.XX.XX', auth=('admin','xxxxxx'), transport='ntlm', server_cert_validation='ignore') ##works
is_shell=True
while is_shell:
is_dir_get_or_create = session.run_cmd(r'if exist "C:\Temp\" (echo yes) else (echo no && mkdir C:\Temp)') ##failed
is_shell=False
请帮帮我
提前致谢
【问题讨论】:
-
确保在您的系统上启用了远程管理。此外,如果它只有安全,那么 5986 才能工作,否则它将在 5985 上。
-
是的,我也试过 5985 也是同样的错误
标签: python-3.x winrm