1
我试图从一个docker容器使用pywinrm工作,但是打到一个连接到远程主机的墙上,我无法找到一个工作的例子,并且不打算使用它没有),但低于就是我从文档和我的Python的基本认识拼凑起来的,希望有人能看到我要去哪里错了使用python&pywinrm从linux连接到powershell使用python&pywinrm
事情我已经检查
- 我检查了我可以通过另一个Windows机器连接使用
Enter-PSSession -ComputerName x.x.x.x -UseSSL -Credential $creds;
- 我试过同时使用python3 & python2并得到相同的错误在这两个
- 我试过的例子here这让我在帖子中相同的错误,即使我从Windows机器安装我自签名的证书(使用接受的答案here添加证书),这是不是令人惊讶没有它,因为没有server_cert_validation ='忽略'参数,但有点奇怪与它
- 我试过base64编码密码作为文档提到它需要它但从来没有在任何例子中使用它
- 我已经尝试添加领域/机器名称的用户名(不在域btw)
以下是python3尝试的详细信息。
版本python3 --version
Python 3.4.2
pip --version
pip 9.0.1 from /usr/local/lib/python3.4/dist-packages (python 3.4)
pip show pywinrm
Name: pywinrm
Version: 0.2.2
Summary: Python library for Windows Remote Management
Home-page: http://github.com/diyan/pywinrm/
Author: Alexey Diyan
Author-email: [email protected]
License: MIT license
Location: /usr/local/lib/python3.4/dist-packages
Requires: six, xmltodict, requests, requests-ntlm
Python代码(open_winrm.py)
#!/usr/bin/env python3
import winrm
import base64
p = winrm.protocol.Protocol(
endpoint='https://<some_ip_here>:5986/wsman',
transport='ssl',
username='<some_username_here>',
password='<some_password_here>',
server_cert_validation='ignore')
shell_id = p.open_shell()
command_id = p.run_command(shell_id, 'ipconfig', ['/all'])
std_out, std_err, status_code = p.get_command_output(shell_id, command_id)
p.cleanup_command(shell_id, command_id)
p.close_shell(shell_id)
结果
File "./open_winrm.py", line 13, in <module>
shell_id = p.open_shell()
File "/usr/local/lib/python3.4/dist-packages/winrm/protocol.py", line 132, in open_shell
res = self.send_message(xmltodict.unparse(req))
File "/usr/local/lib/python3.4/dist-packages/winrm/protocol.py", line 207, in send_message
return self.transport.send_message(message)
File "/usr/local/lib/python3.4/dist-packages/winrm/transport.py", line 190, in send_message
raise InvalidCredentialsError("the specified credentials were rejected by the server")
winrm.exceptions.InvalidCredentialsError: the specified credentials were rejected by the server
Dockerfile
FROM node:7.7.3
ENV DEBCONF_NONINTERACTIVE_SEEN="true" \
DEBIAN_FRONTEND="noninteractive"
RUN apt-get update && \
apt-get -y upgrade && \
apt-get -y autoremove && \
apt-get clean
RUN apt-get install -y etherwake locales locales-all python3 && \
curl https://bootstrap.pypa.io/get-pip.py | python3 && \
python3 -m pip install pywinrm