python編程實現對遠程執行bat文件時遇到的錯誤
問題描述
代碼如下
# -*- 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.110', username='Administrator',password='12345678')報錯情況如下: C:Python27python.exe D:/untitled/遠程連接.pyTraceback (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_access_denied: <x_wmi: Unexpected COM Error (-2147352567, ’xb7xa2xc9xfaxd2xe2xcdxe2xa1xa3’, (0, u’SWbemLocator’, u’u62d2u7eddu8bbfu95eeu3002 ’, None, 0, -2147024891), None)>None
這是什么錯誤呢,有哪個高手幫忙解答一下,謝謝~
問題解答
回答1:錯誤提示得很清楚,拒絕訪問
回答2:我說說看到的一個錯
cmd_callbat = 'start c:123.bat'
回答3:print 'xb7xa2xc9xfaxd2xe2xcdxe2xa1xa3'發生意外。
一個個排除了,要么是連接意外, 先不執行腳本,執行一個最簡單的cmd 命令,dir 之類的,看看有沒有正確返回。然后,再執行腳本,看看
相關文章:
1. python 計算兩個時間相差的分鐘數,超過一天時計算不對2. javascript - 使用form進行頁面跳轉,但是很慢,如何加一個Loading?3. angular.js - 輸入郵箱地址之后, 如何使其自動在末尾添加分號?4. angular.js - angularjs 注入模塊報錯 很怪異... 求解惑5. javascript - JS 里面的 delete object.key 到底刪除了什么?6. javascript - ES6規范下 repeat 函數報錯 Invalid count value7. docker-compose中volumes的問題8. javascript - html5的data屬性怎么指定一個function函數呢?9. javascript - 后臺管理系統左側折疊導航欄數據較多,怎么樣直接通過搜索去定位到具體某一個菜單項位置,并展開當前菜單10. html5 - 為什么使使用vue cli 腳手架,post-css 沒有自動對css3屬性自動添加瀏覽器前綴呢?
