使用python的wmi進行遠程連接的時候報錯
問題描述
# -*- coding: utf-8 -*-import wmi,jsonimport timeimport tracebackimport syslogfile = ’logs_%s.txt’ % time.strftime(’%Y-%m-%d_%H-%M-%S’, time.localtime())#遠程執行bat文件def call_remote_bat(ipaddress,username,password): try:#用wmi連接到遠程服務器conn = wmi.WMI(computer=ipaddress, user=username, password=password)filename=r'C:123.bat' #此文件在遠程服務器上cmd_callbat = 'start c:123.bat'conn.Win32_Process.Create(CommandLine=cmd_callbat) #執行bat文件print '執行成功!'return True except Exception,e:log = open(logfile, ’a’)log.write((’%s, call bat Failed!rn’) % ipaddress)log.close()print traceback.print_exc(file=sys.stdout)return False return Falseif __name__==’__main__’: call_remote_bat(ipaddress='192.168.110.131', username='Administrator', password='123456')
以上是遠程連接的代碼,運行和報錯如下:
Traceback (most recent call last): File 'D:/untitled/???????.py', line 11, in call_remote_bat
conn = wmi.WMI(computer=ipaddress, user=username, password=password)
File 'C:Python27libsite-packageswmi.py', line 1290, in connect
handle_com_error ()
File 'C:Python27libsite-packageswmi.py', line 241, in handle_com_error
raise klass (com_error=err)
x_wmi: <x_wmi: Unexpected COM Error (-2147352567, ’xb7xa2xc9xfaxd2xe2xcdxe2xa1xa3’, (0, u’SWbemLocator’, u’RPC u670du52a1u5668u4e0du53efu7528u3002 ’, None, 0, -2147023174), None)>None
這是什么錯誤,有哪位高手可以解答一下
這個報錯我在主機ping通虛擬機(遠程計算機)之后,運行代碼,還是以上的報錯,這又是什么情況呢?哪位高手幫忙解答一下,謝謝。
問題解答
回答1:看錯誤提示是服務器不可用啊,你需要確保你遠程的服務器可以ping通,另外用戶和密碼要對的上。
回答2:b’xb7xa2xc9xfaxd2xe2xcdxe2xa1xa3’.decode(’gbk’)’發生意外。’u’RPC u670du52a1u5668u4e0du53efu7528u3002 ’’RPC 服務器不可用。 ’
相關文章:
1. docker - 各位電腦上有多少個容器啊?容器一多,自己都搞混了,咋辦呢?2. docker網絡端口映射,沒有方便點的操作方法么?3. docker start -a dockername 老是卡住,什么情況?4. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?5. docker gitlab 如何git clone?6. dockerfile - [docker build image失敗- npm install]7. docker不顯示端口映射呢?8. docker-compose 為何找不到配置文件?9. docker內創建jenkins訪問另一個容器下的服務器問題10. 最新版本的PhpStudy支持64位的PHP嗎? 為什么我把64位的PHP放入后,后臺收不到POST
