2017-04-18 120 views
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 

回答

0

最後我放棄了pywinrm,因爲我永遠無法使用ruby與winrm gem進行第一次嘗試