使用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鏡像push報錯2. angular.js - angular內容過長展開收起效果3. angular.js - angularjs的自定義過濾器如何給文字加顏色?4. python 怎樣用pickle保存類的實例?5. python的前景到底有大?如果不考慮數據挖掘,機器學習這塊?6. MySQL中無法修改字段名的疑問7. javascript - 微信小程序限制加載個數8. 大家好,請問在python腳本中怎么用virtualenv激活指定的環境?9. linux - 升級到Python3.6后GDB無法正常運行?10. 并發模型 - python將進程池放在裝飾器里為什么不生效也沒報錯
