使用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 for Mac 創建的dnsmasq容器連不上/不工作的問題2. javascript - QWebEngineView 如何爬 angular 的動態數據?3. javascript - 使用angular 的ui-sref 中出現了中文參數,點擊跳轉后瀏覽器的地址欄里出現轉義后的%AE....%a%44. java - ConcurrentHashMap中的get()方法為什么可以不加鎖?5. java - 郵箱如何發送html內容6. html5 - 這個代碼顯示功能如何實現?7. javascript - 用JS 七牛上傳圖片出現文件已存在的錯誤(file exists)8. 工作近5年,3年Java Web ,近2年前端,未來何去何從?9. css3 - 圖片等比例縮放10. java - 字節流轉成字符串之后,在通過字符串轉成字節流后的文件為什么會不一樣?
