【发布时间】:2017-09-14 12:49:55
【问题描述】:
我正在尝试使用 docker 容器中的 pywinrm 让 python 远程 powershell 工作,但是碰到连接到远程主机的墙我无法在 ssl 工作的任何地方找到一个工作示例(并且不会在没有它的情况下使用它)但下面是我从文档和我对 python 的基本理解中拼凑出来的内容,希望有人能看出我哪里出错了
我检查过的事情
- 我检查了我是否可以使用
Enter-PSSession -ComputerName x.x.x.x -UseSSL -Credential $creds;通过另一台 Windows 机器进行连接 - 我尝试过同时使用 python3 和 python2 并得到相同的错误
- 我已经尝试了示例here,即使我从 Windows 机器安装了我的自签名证书(使用接受的答案here 添加证书),它也会在帖子中得到相同的错误,这不是没有它令人惊讶,因为没有 server_cert_validation='ignore' 参数,但有点奇怪
- 我已尝试对密码进行 base64 编码,因为文档中提到它需要它,但从未在任何示例中使用它
- 我已尝试将领域/机器名称添加到用户名(不是在域上)
以下是 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: alexey.diyan@gmail.com
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
【问题讨论】:
标签: python linux powershell ssl