Skip to content

winrm.exceptions.UnauthorizedError: 401 Unauthorized. basic auth failed #6

@bhupal1reddy

Description

@bhupal1reddy

Hello I am a new bee to Python .. Just putting baby steps into Python world.

Here is what I am trying to do ..

  1. I have a RHEL 6.5 host on which I have Python 2.6.6 installed.
  2. I am using a "winrm" module to connect to a remote windows host to execute a command "ipconfig/all".

Code:-

START

!/usr/bin/python

import getpass
import sys
import winrm

user = "username"
host = "x.x.x.x"
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)

END

I am getting the following error when executing the above script .. Could anyone please help..

ERROR:-

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

Please help...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions