1、问题原因
各位大老好我在运行python winrm链接没有问题,但是执行crm时间报错
2、链接代码
import winrm
s=winrm.Session('http://11.245.8.234:5985/wsman',auth=('zhangh','mima'))
print(s)
返回
<winrm.Session object at 0x0000013B9A9A5480>链接成功
3、报错
但是只要加上 run_ps 以及 run_cmd 就会报错
import winrm
s=winrm.Session('http://11.245.8.234:5985/wsman',auth=('zhangh','mima'))
r=s.run_ps('dir')
r=s.run_cmd('cd /d d: & test.bat')
print(s)
报错信息:
Traceback (most recent call last):
File "E:\项目\djangoProject3\venv\lib\site-packages\winrm\transport.py", line 340, in _send_message_request
response.raise_for_status()
File "E:\项目\djangoProject3\venv\lib\site-packages\requests\models.py", line 960, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: for url: http://192.168.0.193:5985/wsman
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "E:\项目\djangoProject3\cs.py", line 11, in <module>
r=s.run_ps('dir')
File "E:\项目\djangoProject3\venv\lib\site-packages\winrm\__init__.py", line 52, in run_ps
rs = self.run_cmd('powershell -encodedcommand {0}'.format(encoded_ps))
File "E:\项目\djangoProject3\venv\lib\site-packages\winrm\__init__.py", line 39, in run_cmd
shell_id = self.protocol.open_shell()
File "E:\项目\djangoProject3\venv\lib\site-packages\winrm\protocol.py", line 166, in open_shell
res = self.send_message(xmltodict.unparse(req))
File "E:\项目\djangoProject3\venv\lib\site-packages\winrm\protocol.py", line 243, in send_message
resp = self.transport.send_message(message)
File "E:\项目\djangoProject3\venv\lib\site-packages\winrm\transport.py", line 334, in send_message
response = self._send_message_request(prepared_request, message)
File "E:\项目\djangoProject3\venv\lib\site-packages\winrm\transport.py", line 344, in _send_message_request
raise InvalidCredentialsError("the specified credentials were rejected by the server")
winrm.exceptions.InvalidCredentialsError: the specified credentials were rejected by the server
求帮忙解惑谢谢了!