GithubHelp home page GithubHelp logo

pywinrm's People

Contributors

alexpilotti avatar badcure avatar benschweizer avatar cchurch avatar cournape avatar dagwieers avatar diyan avatar gemagomez avatar githubfriction avatar jborean93 avatar jijojv avatar lukas-bednar avatar maxk-fortscale avatar moriyoshi avatar mschweyen avatar nephomaniac avatar nir0s avatar nitzmahone avatar nmaludy avatar rustyscottweber avatar timgates42 avatar tstone2077 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pywinrm's Issues

suggestion: start tagging releases

It seems that activity in this repo has picked up again and some major changes are planned. I would request that before any further radical changes are done, stamp a release (tag) with a version number so that any projects that rely on the library can be installed on a stable (or at least known) point in time. I am relying on a forked version, but would like to point back to the original repo or pypi at some point. thanks

auth problem....

Hi,

I tried to pywinrm in OS X terminal. but receive error.

how can i using command T.T

tried to commands.
s = winrm.Session('http://ad_ip:5985/wsman', auth=('ad_account', 'password'))
or
s = winrm.Session('http://ad_ip:5985/wsman', auth=('administrator', 'password'))
and
r = s.run_cmd(ps_script)

winrm.exceptions.UnauthorizedError: 401 Unauthorized. PS C:\Users\Administrator> winrm get winrm/config Config MaxEnvelopeSizekb = 500 MaxTimeoutms = 60000 MaxBatchItems = 32000 MaxProviderRequests = 4294967295 Client NetworkDelayms = 5000 URLPrefix = wsman AllowUnencrypted = false Auth Basic = true Digest = true Kerberos = true Negotiate = true Certificate = true CredSSP = false DefaultPorts HTTP = 5985 HTTPS = 5986 TrustedHosts Service RootSDDL = O:NSG:BAD:P(A;;GA;;;BA)(A;;GR;;;IU)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;;;WD) MaxConcurrentOperations = 4294967295 MaxConcurrentOperationsPerUser = 1500 EnumerationTimeoutms = 240000 MaxConnections = 300 MaxPacketRetrievalTimeSeconds = 120 AllowUnencrypted = false Auth Basic = true Kerberos = true Negotiate = true Certificate = false CredSSP = false CbtHardeningLevel = Relaxed DefaultPorts HTTP = 5985 HTTPS = 5986 IPv4Filter = * IPv6Filter = * EnableCompatibilityHttpListener = false EnableCompatibilityHttpsListener = false CertificateThumbprint AllowRemoteAccess = true Winrs AllowRemoteShellAccess = true IdleTimeout = 7200000 MaxConcurrentUsers = 10 MaxShellRunTime = 2147483647 MaxProcessesPerShell = 25 MaxMemoryPerShellMB = 1024 MaxShellsPerUser = 30

Exception raised while getting the output. "winrm.exceptions.WinRMTransportError: 500 WinRMTransport. Bad HTTP response returned from server. Code 500"

During the get_command_output(self, shell_id, command_id), the first call to "_raw_get_command_output(shell_id, command_id)"
returns as it should, however since the command is still running the command will run a second time. On the second call, I get the following error.


 stdout, stderr, return_code, command_done = self.protocol._raw_get_command_output(self.shell_id, self.command_id)
  File "C:\Python27\lib\site-packages\winrm\protocol.py", line 293, in _raw_get_command_output
    rs = self.send_message(xmltodict.unparse(rq))
  File "C:\Python27\lib\site-packages\winrm\protocol.py", line 173, in send_message
    return self.transport.send_message(message)
  File "C:\Python27\lib\site-packages\winrm\transport.py", line 101, in send_message
    raise WinRMTransportError('http', error_message)
winrm.exceptions.WinRMTransportError: 500 WinRMTransport. Bad HTTP response returned from server. Code 500

GSSError: ((' Miscellaneous failure (see text)', 851968) while trying to use domain credentials

It seems that ansible is unable to connect to windows hosts even when it does have a valid kerberos token.

Ansible 1.9.4 on OS X 10.11, klist returns a valid token.

As a note, I observed that ansible will try to connect only if I do specify ansible_ssh_user variable. The same setup works OK if I try to use a local-user account instead of a domain account but we do really need domain accounts in order to be able to execute some restricted commands.

ansible_ssh_user: [email protected]
ansible_ssh_port: 5985
ansible_connection: winrm
ansible_winrm_scheme: http

Here is the output

nibbler:ansible sorins$ ansible -vvvv bld-10.eng.example.com -m win_ping
<bld-10.eng.example.com> ESTABLISH WINRM CONNECTION FOR USER:  on PORT 5985 TO bld-10.eng.example.com
<bld-10.eng.example.com> WINRM CONNECT: transport=kerberos endpoint=http://bld-10.eng.example.com:5985/wsman
bld-10.eng.example.com | FAILED => Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/ansible/runner/__init__.py", line 586, in _executor
    exec_rc = self._executor_internal(host, new_stdin)
  File "/usr/local/lib/python2.7/site-packages/ansible/runner/__init__.py", line 789, in _executor_internal
    return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)
  File "/usr/local/lib/python2.7/site-packages/ansible/runner/__init__.py", line 968, in _executor_internal_inner
    conn = self.connector.connect(actual_host, actual_port, actual_user, actual_pass, actual_transport, actual_private_key_file, delegate_host)
  File "/usr/local/lib/python2.7/site-packages/ansible/runner/connection.py", line 52, in connect
    self.active = conn.connect()
  File "/usr/local/lib/python2.7/site-packages/ansible/runner/connection_plugins/winrm.py", line 140, in connect
    self.protocol = self._winrm_connect()
  File "/usr/local/lib/python2.7/site-packages/ansible/runner/connection_plugins/winrm.py", line 96, in _winrm_connect
    protocol.send_message('')
  File "/usr/local/lib/python2.7/site-packages/winrm/protocol.py", line 193, in send_message
    return self.transport.send_message(message)
  File "/usr/local/lib/python2.7/site-packages/winrm/transport.py", line 269, in send_message
    krb_ticket = KerberosTicket(self.krb_service)
  File "/usr/local/lib/python2.7/site-packages/winrm/transport.py", line 205, in __init__
    kerberos.authGSSClientStep(krb_context, '')
GSSError: ((' Miscellaneous failure (see text)', 851968), ("Server (HTTP/[email protected]) unknown while looking up 'HTTP/[email protected]' (cached result, timeout in 696 sec)", -1765328377))

Develop usable high level API

Sorry for breaking changes in pywinrm library.

I'm developing two level of APIs within library.

Low-level API will be closer to WinRM protocol and should not be used by end user unless you would like have full control.

Standard API is inspired on requests and envoy libraries by Kenneth Reitz.

Right now standard API is still unstable and I'm open to any suggestions and improvements.

Standard API example (in progress)

import pywinrm

s = pywinrm.Session('windows-host', auth=('john.smith', 'secret'))
r = s.run_cmd('ipconfig', ['/all'])
>>> r.status_code
0
>>> r.std_out
Windows IP Configuration

   Host Name . . . . . . . . . . . . : WINDOWS-HOST
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
...
>>> r.std_err

Low-level API example

from pywinrm.protocol import Protocol

p = Protocol(
    endpoint='http://windows-host:5985/wsman',
    transport='plaintext',
    username='john.smith',
    password='secret')
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)

SSL Certificate Verification Failures with Python 2.7.9+

Due to an update in the default behavior of Python with ssl http clients in the latest releases (2.7.9), ssl verification is now performed by default. Additionally, I was unable to make the verification work by adding the certificate to my system ca trust store.

I think the original behavior should be left as default and a new option should be added to support verification.

See this page for details: https://www.python.org/dev/peps/pep-0476/

Rename 'transports' parameter to 'authentication'

Hi All,

The current Protocol 'transport' argument accepts 'plaintext', 'ssl', and 'kerberos'
As we know, these not transports, but HTTP authentication mechanisms: basic, certificate and kerberos.

class Protocol(object):
..
def __init__(self, endpoint, transport='plaintext', username=None..

The transport protocol is already in protocol portion of the endpoint url (http:// or https://)

So, shouldn't this parameter be called 'authentication' or something?

Thanks
Ian

Can run sample with Kerberos only if I KINIT first

I am testing the code sample below, but I can only run this code successfully if I first KINIT [email protected] from BASH and provide the credentials.

s = winrm.Session('server.company.com', transport='kerberos', auth=('[email protected]', 'password'))
r = s.run_cmd('ipconfig', ['/all'])

Otherwise I get this error:

winrm.exceptions.WinRMTransportError: 500 WinRMTransport. Kerberos-based authentication was failed. Code 401

It should be noted that I had to Allow unencrypted traffic in the Group Policy for WinRM Service in order to make it work even with the KINIT credential in place. That singular change was all that necessary in order to make this work. Just need to get this part sorted.

pywinrm pollutes teminal output

First, thanks for this library, it is really cool. But I discovered that it pollutes stdout or stderr with XML content (did not investigate further). Can this output be somehow muted? It is making our jenkins jobs' results harder to read :)

Provide pywinrm RPM in Fedora/EPEL repos

Hi @diyan,

I find pywinrm an awesome library to interact with Windows, that's why I'm using it as part of a pull request to oz (clalancette/oz#174) to implement the customization phase for Windows guests.

Unfortunately, one of the stoppers for the PR is that pywinrm is not packaged in the Fedora/EPEL repositories, where the oz RPM and its dependencies are available.

Said that, what do you think about adding support to package pywinrm as an RPM make it available in Fedora/EPEL? (more info: https://fedoraproject.org/wiki/Join_the_package_collection_maintainers)

Thanks!

Connection by IP is not working

>>> import winrm
>>> s = winrm.Session('192.168.173.206', auth=('Administrator', 'password'))
>>> r = s.run_cmd('ver')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/opt/zenoss/lib/python2.7/site-packages/winrm/__init__.py", line 24, in run_cmd
    shell_id = self.protocol.open_shell()
  File "/opt/zenoss/lib/python2.7/site-packages/winrm/protocol.py", line 103, in open_shell
    rs = self.send_message(xmltodict.unparse(rq))
  File "/opt/zenoss/lib/python2.7/site-packages/winrm/protocol.py", line 173, in send_message
    return self.transport.send_message(message)
  File "/opt/zenoss/lib/python2.7/site-packages/winrm/transport.py", line 73, in send_message
    response = urlopen(request, timeout=self.timeout)
  File "/opt/zenoss/lib/python2.7/urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "/opt/zenoss/lib/python2.7/urllib2.py", line 386, in open
    protocol = req.get_type()
  File "/opt/zenoss/lib/python2.7/urllib2.py", line 248, in get_type
    raise ValueError, "unknown url type: %s" % self.__original
ValueError: unknown url type: 192.168.173.206

No way to send stdin to running process.

I love what is here and would like to know more about this project to expand the capability of what pywinrm can do. Most importantly, I want to add the capability to send stdin to the running process. Can this be easily done? or is this impossible?

Kerberos auth. Message encryption. Status update

After trying different approaches of using Kerberos transport for pywinrm library ended up with writing my own binding.

I did managed to work with authentication itself by using https://pypi.python.org/pypi/kerberos library but main challenge here is to implement message encryption.

Looks like neither kerberos, python-krb5 nor python-krbV binding did not expose required API.

I was really amazed how CFFI library can help you with writing bindings for Python.

For everyone who is interested please go ahead check source code here:

https://github.com/diyan/pywinrm/blob/kerberos_cffi/tests/test_kerberos_api.py

Note this version does not work at all but I'm hoping to get this stuff usable soon.

File Upload

Hi,
Will there be any possibility of doing file transfer using pywinrm? I need to upload a
file to Windows Machine from my Python Program.

Thanks
Vipul

Error: Could not run: Could not find file <filepath + filename>

I am trying to run a puppet provisioning manifest file. Ex. C:\manifests\dothis.pp.
The entire command is 'puppet apply C:\manifests\dothis.pp'.
I receive: Error: Could not run: Could not find file C:\manifests\dothis.pp.
The file exists. If I paste the file path and name from the error directly into the VM, things work as expected.
I have looked for non-printable chars, etc. in the full command. It all looks good. I am at a loss.

Thanks,
-Mark

many TIME_WAIT in managed host

capture

when i run repeatedly the below codes, i will get the upon picture(many TIME_WAIT):

    import winrm
    ps_script = """$strComputer = $Host
    Clear
    $RAM = WmiObject Win32_ComputerSystem
    $MB = 1048576

    "Installed Memory: " + [int]($RAM.TotalPhysicalMemory /$MB) + " MB" """

    s = winrm.Session('10.0.0.8', auth=('Administrator', '1'))
    r = s.run_ps(ps_script)
    print r.std_out

the managed host is windows 2003 with winrm 1.1

Does this support Negotiate/Ntlm authentication

Hi,

I am new to Windows RM, but I found your library and wanted to use it to replace some complex code I inherited. We are authenticating using the Negotiate/Ntlm option. Does pywinrm support this? If so, do you have an example usage? So far, I just keep getting "401 Unauthorized".

Thanks!!
Kathy

Python 3.4.1 - incorrect representation of strings on std_out

When running a command using the example provided on the github project page, output was formatted as follows -

Example

b' Volume in drive C is OSDisk\r\n'b' Volume Serial Number is CE5D-2D9B\r\n\r\n Directory of C:\Users\winrmtest\r\n\r\n03/08/2015 12:53

.\r\n03/08/2015 12:53 ..\r\n14/07/2009 03:34 Desktop\r\n03/08/2015 12:53 Documents\r\n14/07/2009 03:34 Downloads\r\n14/07/2009 03:34 Favorites\r\n14/07/2009 03:34 Links\r\n14/07/2009 03:34 Music\r\n14/07/2009 03:34 Pictures\r\n14/07/2009 03:34 Saved Games\r\n14/07/2009 03:34 Videos\r\n 0 File(s) 0 bytes\r\n 11 Dir(s) 42,674,880,512 bytes free\r\n'

For longer outputs, there would be multiple b' entries within the context owing to the string append that takes place.

I made the following in protocol.py which seem to resolve the issue in question -

Before:
stdout += str(base64.b64decode(stream_node.text.encode('ascii')))

After:
stdout += base64.b64decode(stream_node.text.encode('ascii')).decode('utf-8')

Example output after changes:

Volume in drive C is OSDisk
Volume Serial Number is CE5D-2D9B

Directory of C:\Users\winrmtest

03/08/2015 12:53

.
03/08/2015 12:53 ..
14/07/2009 03:34 Desktop
03/08/2015 12:53 Documents
14/07/2009 03:34 Downloads
14/07/2009 03:34 Favorites
14/07/2009 03:34 Links
14/07/2009 03:34 Music
14/07/2009 03:34 Pictures
14/07/2009 03:34 Saved Games
14/07/2009 03:34 Videos
0 File(s) 0 bytes
11 Dir(s) 42,674,782,208 bytes free

Pull request submitted

Cant Authenticate with Basic Authentication - 401 Unauthorized. basic auth failed

I am trying to authenticate using basic authentication via this code, I am able to manually login to the Windows host in question but when I try to login via the script it fails here is the code below which I am using...

!/usr/bin/python

import getpass
import sys
import winrm

user = r"DOMAIN\xyz"
host = "windows.example.com"
print("Enter password for User [%s]" % user)
pw = getpass.getpass()

from winrm.protocol import Protocol
p = Protocol(
endpoint='http://'+host+':5985/wsman',
transport='plaintext',
username=user,
password=pw)
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)

print std_out
print std_err
print status_code

p.cleanup_command(shell_id, command_id)
p.close_shell(shell_id)

C:\Users>winrm get winrm/config/service
Service
RootSDDL = O:NSG:BAD:P(A;;GA;;;BA)(A;;GR;;;IU)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;
;;WD)
MaxConcurrentOperations = 4294967295
MaxConcurrentOperationsPerUser = 1500
EnumerationTimeoutms = 240000
MaxConnections = 300
MaxPacketRetrievalTimeSeconds = 120
AllowUnencrypted = true
Auth
Basic = true
Kerberos = true
Negotiate = true
Certificate = false
CredSSP = false
CbtHardeningLevel = Relaxed
DefaultPorts
HTTP = 5985
HTTPS = 5986
IPv4Filter = *
IPv6Filter = *
EnableCompatibilityHttpListener = false
EnableCompatibilityHttpsListener = false
CertificateThumbprint
AllowRemoteAccess = true

Error ๐Ÿ‘Ž
[root@# ./windows.py
Enter password for User [DOMAIN\breddy]
Password:
Traceback (most recent call last):
File "./windows.py", line 18, in
shell_id = p.open_shell()
File "/usr/lib/python2.6/site-packages/winrm/protocol.py", line 118, in open_shell
rs = self.send_message(xmltodict.unparse(rq))
File "/usr/lib/python2.6/site-packages/winrm/protocol.py", line 190, in send_message
return self.transport.send_message(message)
File "/usr/lib/python2.6/site-packages/winrm/transport.py", line 99, in send_message
raise UnauthorizedError(transport='plaintext', message=ex.msg)
winrm.exceptions.UnauthorizedError: 401 Unauthorized. basic auth failed

Auth using AD username?

Is it possible to authenticate using an Active Directory (AD) username?

>>> import winrm
>>> s = winrm.Session('192.168.123.158', auth=('example.com\Administrator', 'V@grant'))
>>> s.run_cmd('echo test')
Traceback (most recent call last):
  File "<ipython-input-10-231983453a9e>", line 1, in <module>
    s.run_cmd('echo test')
  File "/home/jakob/pywinrm/winrm/__init__.py", line 29, in run_cmd
    shell_id = self.protocol.open_shell()
  File "/home/jakob/pywinrm/winrm/protocol.py", line 118, in open_shell
    rs = self.send_message(xmltodict.unparse(rq))
  File "/home/jakob/pywinrm/winrm/protocol.py", line 190, in send_message
    return self.transport.send_message(message)
  File "/home/jakob/pywinrm/winrm/transport.py", line 99, in send_message
    raise UnauthorizedError(transport='plaintext', message=ex.msg)
UnauthorizedError: 401 Unauthorized. basic auth failed

Using winexe works:

$  winexe -U 'example.com\Administrator'%V@grant //192.168.123.158 'cmd.exe /c echo test'
test

Using the local administrator also works:

>>> import winrm
>>> s = winrm.Session('192.168.123.158', auth=('Administrator', 'V@grant'))
>>> s.run_cmd('echo test')
<Response code 0, out "test
", err "">

kind regards,
Jakob

Possible Installation Bug

I believe I am doing things correctly and this is not working. Any help is appreciated.

[user@build-1 workspace]$ sudo pip install http://github.com/diyan/pywinrm/archive/master.zip
Downloading/unpacking http://github.com/diyan/pywinrm/archive/master.zip
Downloading master.zip
Running setup.py egg_info for package from http://github.com/diyan/pywinrm/archive/master.zip
Downloading/unpacking xmltodict (from pywinrm==0.0.3)
Downloading xmltodict-0.9.0.tar.gz
Running setup.py egg_info for package xmltodict
Downloading/unpacking isodate (from pywinrm==0.0.3)
Downloading isodate-0.5.0.tar.gz
Running setup.py egg_info for package isodate
Installing collected packages: xmltodict, isodate, pywinrm
Running setup.py install for xmltodict
Running setup.py install for isodate
Running setup.py install for pywinrm
Successfully installed xmltodict isodate pywinrm
Cleaning up...
[user@build-1 workspace]$ python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import pywinrm
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named pywinrm

winrm: slow file transfer speeds - a possible workaround?

Hi there,
I've been using your module behind ansible for provisioning a windows host. However the most slow part seems to be the file transfers / upload over winrm protocol.

Due to the way ansible implements it's windows support (exclusively through winrm)... it would be best if we could stick to just using py-winrm.

While recently it seems those in another community (who also rely upon winrm) may have stumbled across a marvelous idea. And here it is:

packer-community/winrmcp#6 (comment)

Sorry I don't know if it can be done here. Not really my area of expertise but could you please be so kind as to take a look? It might prove to be a worthwhile avenue of investigation. And generate a clear improvement in file transfer speeds. Many thanks for any interest.

Error: POST data should be bytes or an iterable of bytes

I'm using cPython 3.5 on Mac OS X. When I try to run a PowerShell script remotely, I get an exception:

TypeError: POST data should be bytes or an iterable of bytes. It cannot be of type str.

image

Any thoughts on what could cause this? The repro is in the screenshot.

Cheers,
Trevor Sullivan
Microsoft MVP: PowerShell

Switch from xmlwitch into xmltodict library

I did a fork of xmlwitch library with Python 3 support and tried push changes into upstream project but looks like this project is not maintained anymore.

So, intead of support own fork I'm gong to switch into xmltodict library for several reasons:

  1. More active development
  2. Python 3 support out of box
  3. Based on dictionary and not on context manager
  4. Provides API for both parsing and writing

Domain Authentication without Kerberos

This is more of an information request than an issue. I've got pywinrm working, but I have a specific need to authenticate using a domain account and password which is not know to me in advance.

I understand that the Negotiate authentication method might support this. Is this a planned (or even possible) feature?

Can you suggest any way possible to authenticate, using credentials specified at run time, preferably without using Kerberos at all?

Thanks!

Installed but get unrelenting error

I have attempted the most basic call and receive this error:
error

I can connect to the server from Windows Servers without issue. No firewall rules or anything in the way to block connectivity.

Live stdout and stderr feed

First of all thanks on the great library, we use it constantly. However i feld that i could really use some live feed of stdout and stderr from the local machine; So I've added some really basic support for writing into streams. This enables to pipe the stdour and stderr into some stream (providied by the user).
Note this is works only when the response isn't in xml format (as xml stream needs to be decoded).

Pull request submitted.

Unable to connect to the windows host. : winrm.exceptions.WinRMTransportError: 500 WinRMTransport. [Errno 111] Connection refused

Could you please help me with this here..

import winrm
s = winrm.Session('windowshost', auth=('username', 'password'))
r = s.run_cmd('ipconfig', ['/all'])
Traceback (most recent call last):
File "", line 1, in
File "winrm/init.py", line 28, in run_cmd
shell_id = self.protocol.open_shell()
File "winrm/protocol.py", line 103, in open_shell
rs = self.send_message(xmltodict.unparse(rq))
File "winrm/protocol.py", line 173, in send_message
return self.transport.send_message(message)
File "winrm/transport.py", line 103, in send_message
raise WinRMTransportError('http', ex.reason)
winrm.exceptions.WinRMTransportError: 500 WinRMTransport. [Errno 111] Connection refused

Instructions to use Kerberos ?

Can anybody provide an example on how to get kerberos working for pywinrm ? I am trying to use this with Ansible 1.7 to manage windows server remotely and have spent half day on this topic online but could not find anything.

Document isodate dependency

I followed the instructions on RHEL7 and was greeted with:

ImportError: No module named isodate.isoduration

This non-standard module dependency should be documented in the README.md file.

WinRMTransportError error in multiprocess.

I tend to fire some commands repeatedly in a loop. After 3 or 4th loop it gives following error. I am running the loop in Process using multiprocessing module. For single operations it works fine but in a repeated loop it throws exception. Is it some threading problem here ?

File "/usr/local/lib/python2.7/dist-packages/pywinrm-0.0.2dev-py2.7.egg/winrm/protocol.py", line 262, in get_command_output
self._raw_get_command_output(shell_id, command_id)
File "/usr/local/lib/python2.7/dist-packages/pywinrm-0.0.2dev-py2.7.egg/winrm/protocol.py", line 280, in _raw_get_command_output
response = self.send_message(str(node))
File "/usr/local/lib/python2.7/dist-packages/pywinrm-0.0.2dev-py2.7.egg/winrm/protocol.py", line 160, in send_message
return self.transport.send_message(message)
File "/usr/local/lib/python2.7/dist-packages/pywinrm-0.0.2dev-py2.7.egg/winrm/transport.py", line 166, in send_message
raise WinRMTransportError(error_message)
WinRMTransportError: Kerberos-based authentication was failed. Code 500

Not able to use this module in Python 3.4

I'm trying with executing the following sample code
s = winrm.Session('windows-host.example.com', auth=('john.smith', 'secret'))
r = s.run_cmd('ipconfig', ['/all'])

I faced "TypeError: POST data should be bytes or an iterable of bytes. It cannot be of type str" error. After googling the issue, I found that that the POST data should be encoded and hence I added a patch in urllib to encode the data.

After the patch, I'm getting "ValueError: AbstractBasicAuthHandler does not support the following scheme: 'Negotiate'". While debugging I found that there are two values for WWW-authenticate in the headers
WWW-Authenticate: Negotiate
WWW-Authenticate: Basic realm="WSMAN"
and urllib is taking the first value (Negotiate)

How the headers are passed to urllib and is there any options to modify it? How can I solve the issue?

Produce releases?

Hello,

I'm looking at packaging this module for Debian, and noticed that you are producing regular releases but suggest that people download directly from master.

I wondered if you would consider making releases too, since this would make it easier to keep track of versions installed. We can work around this by renaming master.tar.gz to include 0.0.3+20150522, but this is a bit ugly and needs manual intervention.

Thanks for your work on this project!

P.S. the bug report about adding this to Debian is https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760962

README example does not seem to work

I attempted to get the readme example to work but could not. I think this may be because the library is a work in progress?

Here is an example I did get to work assuming the winrm directory is in the sys.path ...

cmd = "dir c:\"
address = "123.123.123.123"
user = "administrator"
password = "zzzzzzzzzzz"

import winrm
from winrm import winrm_service

winrm = winrm_service.WinRMWebService(endpoint=address, transport='plaintext',
    username=user, password=password)

shell_id = winrm.open_shell()
command_id = winrm.run_command(shell_id, cmd)
buff, stderr, return_code = winrm.get_command_output(shell_id, command_id)

winrm.cleanup_command(shell_id, command_id)
winrm.close_shell(shell_id)

print buff
print stderr
print return_code

pywinrm transport using requests

Below is email that I've got from @cchurch.

I'm not entirely sure what approach we should follow - try to stick with Python stdlib or use requests.

On the one hand we may keep dependencies as less as possible and may even consider to concatenate all sources into single super-module like I saw in defnull/bottle and amoffat/sh.

It could be very convenient for Linux system administrators just do a wget/curl and start using this library at almost any Linux box right away.

On the other hand we may start to use super popular library that everyone knows which will make some things for us much simpler. Code will be simpler than now and we will have less warries on Python 2/3 compatibility at transport level.

I would happy to hear any opinions, especially from people thad did contributions ( @alexpilotti @cournape @gemagomez @bigschwan @pdunnigan and others ) .

@cchurch:
I've taken a shot at rewriting the transport class to use requests (and requests-kerberos and a modified copy of requests-ntlm) for the following reasons:

  • Keeping the connection alive to avoid reconnecting or re-authenticating for each message
  • Adding support for NTLM authentication
  • Trying multiple authentication schemes based on what the server supports (e.g. trying kerberos but falling back to NTLM or basic)

See https://github.com/cchurch/pywinrm/blob/transport-refactor/winrm/requests_transport.py

It works for me but hasn't been extensively tested yet, doesn't fully implement certificate auth, etc.

I would be interested in your feedback and comments - do you think you'd be interested in including these changes in the project (with additional cleanup and tests)?

encoding issue

Hi,
I am getting this issue when i execute the script

TypeError: POST data should be bytes or an iterable of bytes. It cannot be of ty
pe str

import winrm
s = winrm.Session('windows-host.example.com', auth=('john.smith', 'secret'))
r = s.run_cmd('ipconfig', ['/all'])

Please help me how to solve this issue asap.

Pywinrm breaks hyper-v connectivity

Hi,

appereantly I have this issue that i'am unable to debug. I'am using pywinrm to manage hyper-v vms on our dev hyper-v server (2012 r2 version). Everything worked just fine untill yesteday. Whenever I try to run even simple command with winrm session it raises an exception:

Traceback (most recent call last):
File "C:\Python27\lib\site-packages\IPython\core\interactiveshell.py", line 3035, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
ses.run_ps('hostname')
File "C:\Python27\lib\site-packages\winrm__init__.py", line 41, in run_ps
rs = self.run_cmd("powershell -encodedcommand %s" % (base64_script))
File "C:\Python27\lib\site-packages\winrm__init__.py", line 28, in run_cmd
shell_id = self.protocol.open_shell()
File "C:\Python27\lib\site-packages\winrm\protocol.py", line 103, in open_shell
rs = self.send_message(xmltodict.unparse(rq))
File "C:\Python27\lib\site-packages\winrm\protocol.py", line 173, in send_message
return self.transport.send_message(message)
File "C:\Python27\lib\site-packages\winrm\transport.py", line 101, in send_message
raise WinRMTransportError('http', error_message)
WinRMTransportError: 500 WinRMTransport. Bad HTTP response returned from server. Code 500

Sometimes command passes without any problems but it's rare.

It also breaks PowerShell connectivity for some time - in most cases i need to reboot server to regain it.

I am stuck at this point and i have no idea how to fix it so if you have any suggestions please respond.

Thanks

Repoen issue 72

Unfortunatly, I am not a collaborator on this repo.... Yet. Therefore, I cannot reopen
#72
...

documentation lacking ssl transport

Looking at the code, it seems that https is implemented while the documentation is missing any signs of it.

Am I missing something?

Thanks!

Can we haz release tag?

Hello.

Can you please tag 0.0.2dev so it can be used as a release version? This will make it available as a download at "Releases".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.