0
我正在爲了解如何使用pywinrm模塊而打造一個hello world,並且遇到了一個我無法解決的錯誤。如何讓pywinrm連接到遠程Windows機器?
我試過使用兩個版本0.1.1和0.0.3,我在Windows 7上使用Python 3.4.3。
這是程序:
import pywinrm
s = winrm.Session('windows-myhostname', auth=('myusername', 'mypassword'))
r = s.run_cmd('ipconfig', ['/all'])
print (r.status_code)
print (r.std_out)
這是我從例如使用複製在github上,得到了這樣的輸出:
Traceback (most recent call last):
File "My_program_path_here.py", line 18, in <module>
r = s.run_cmd('ipconfig', ['/all'])
File "C:\Python34\lib\site-packages\winrm\__init__.py", line 29, in run_cmd
shell_id = self.protocol.open_shell()
File "C:\Python34\lib\site-packages\winrm\protocol.py", line 121, in open_shell
rs = self.send_message(xmltodict.unparse(rq))
File "C:\Python34\lib\site-packages\winrm\protocol.py", line 193, in send_message
return self.transport.send_message(message)
File "C:\Python34\lib\site-packages\winrm\transport.py", line 108, in send_message
response = self.opener.open(request, timeout=self.timeout)
File "C:\Python34\lib\urllib\request.py", line 461, in open
req = meth(req)
File "C:\Python34\lib\urllib\request.py", line 1112, in do_request_
raise TypeError(msg)
TypeError: POST data should be bytes or an iterable of bytes. It cannot be of type str.
來源:https://github.com/diyan/pywinrm