我试图让python远程PowerShell使用来自docker容器的pywinrm工作,但是碰到连接到远程主机的墙我无法在ssl工作的任何地方找到一个工作示例(并且不会在没有它的情况下使用它)但是下面是我从文档和我对python的基本理解拼凑而成的,希望有人可以看到我出错的地方
Enter-PSSession -ComputerName x.x.x.x -UseSSL -Credential $creds;
以下是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
#!/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
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