使用python的wmi進(jìn)行遠(yuǎn)程連接的時(shí)候報(bào)錯(cuò)
問(wèn)題描述
# -*- coding: utf-8 -*-import wmi,jsonimport timeimport tracebackimport syslogfile = ’logs_%s.txt’ % time.strftime(’%Y-%m-%d_%H-%M-%S’, time.localtime())#遠(yuǎn)程執(zhí)行bat文件def call_remote_bat(ipaddress,username,password): try:#用wmi連接到遠(yuǎn)程服務(wù)器conn = wmi.WMI(computer=ipaddress, user=username, password=password)filename=r'C:123.bat' #此文件在遠(yuǎn)程服務(wù)器上cmd_callbat = 'start c:123.bat'conn.Win32_Process.Create(CommandLine=cmd_callbat) #執(zhí)行bat文件print '執(zhí)行成功!'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')
以上是遠(yuǎn)程連接的代碼,運(yùn)行和報(bào)錯(cuò)如下:
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
這是什么錯(cuò)誤,有哪位高手可以解答一下
這個(gè)報(bào)錯(cuò)我在主機(jī)ping通虛擬機(jī)(遠(yuǎn)程計(jì)算機(jī))之后,運(yùn)行代碼,還是以上的報(bào)錯(cuò),這又是什么情況呢?哪位高手幫忙解答一下,謝謝。
問(wèn)題解答
回答1:看錯(cuò)誤提示是服務(wù)器不可用啊,你需要確保你遠(yuǎn)程的服務(wù)器可以ping通,另外用戶和密碼要對(duì)的上。
回答2:b’xb7xa2xc9xfaxd2xe2xcdxe2xa1xa3’.decode(’gbk’)’發(fā)生意外。’u’RPC u670du52a1u5668u4e0du53efu7528u3002 ’’RPC 服務(wù)器不可用。 ’
相關(guān)文章:
1. css3 - [CSS] 動(dòng)畫(huà)效果 3D翻轉(zhuǎn)bug2. python - Django分頁(yè)和查詢參數(shù)的問(wèn)題3. javascript - 百度echarts series數(shù)據(jù)更新問(wèn)題4. MySQL客戶端吃掉了SQL注解?5. javascript - JS設(shè)置Video視頻對(duì)象的currentTime時(shí)出現(xiàn)了問(wèn)題,IE,Edge,火狐,都可以設(shè)置,反而chrom卻...6. php自學(xué)從哪里開(kāi)始?7. python小白的基礎(chǔ)問(wèn)題 關(guān)于while循環(huán)的嵌套8. 求大神幫我看看是哪里寫(xiě)錯(cuò)了 感謝細(xì)心解答9. phpstady在win10上運(yùn)行10. javascript - 圖片能在網(wǎng)站顯示,但控制臺(tái)仍舊報(bào)錯(cuò)403 (Forbidden)
