How do I troubleshoot a Python script that should log into a Windows server when there are no error messages?

时间:2016-02-03 02:40:28

标签: python linux windows powershell winrm

My Ansible playbooks are not working for my Windows servers (2012). They've never worked correctly. I installed pywinrm (0.1.1) on a CentOS 7 server. I have Python 2.7.5. I have a basic Python script that imports winrm. I have hardcoded the credentials of a local account (not a domain account) to the Windows server. The script should connect to a Windows server, but there are no error messages, and it appears to fail.

import winrm
session = winrm.Session('nameOfWindowsServer', auth=('localUser', 'password'))

I ran a PowerShell script that prepares the server to be used by winrm. I see no activity in the Windows Server event log. How do I get this Python script to log into the Windows Server? It seems to be silently failing. I expect some activity in the Event Viewer of the Windows server.

Update: As the failure was silent, I added to my two line script. I added this third line of Python code:

remotecom = session.run_cmd('ipconfig', ['/all'])

I got this as an error:

Traceback (most recent call last) ... File "/usr/lib/python2.7/site-ackages/winrm/init.py", line 29, in run_cmd ... File "/usr/lib/python2.7/site-ackages/winrm/init.py", line 121, in run_cmd ... File "/usr/lib/python2.7/site-ackages/winrm/init.py", line 193, in run_cmd ... File "/usr/lib/python2.7/site-ackages/winrm/init.py", line 125, in run_cmd ... winrm.exceptions.UnauthorizedError: 401 Unauthorized

Why I am getting this error? Why am I not seeing activity on the Windows server? Should the local user have something to denote it is not a domain login?

0 个答案:

没有答案