使用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. linux - 編譯時提示頭文件#include <mysql/mysql.h>不存在,百度之后也沒解決2. excel - 要如何在號碼前面加0 ? JAVA3. $( "html" ).parent()方法返回一個包含document的集合,而$( "html" ).parents()返回一個空集合 哪位大神來解釋下?4. mysql - SQL能這樣表示嗎?5. javascript - js如何獲取app保存的TOKEN?6. javascript - 問個問題,有木有相關npm包解決類似于jquery的getScript()方法的7. paramiko - Python tempfile生成的文件能不能拷貝到遠程服務器?8. html5 - 有什么好的方法防止微信公眾號發紅包被刷么?9. javascript - canvas畫圖10. javascript - 這段stylus只有前兩行有效
