2014-12-31 61 views
0

我想通過python設置snmpset的值。如何使用python設置snmpset字符串或整數值?

import netsnmp 
snmpcfgfile=netsnmp.Varbind(".1.3.6.1.4.1.171.12.1.2.18.1.1.5.3", 
          "switch.cfg","STRING") 
netsnmp.snmpset(snmpcfgfile, Version=2, DestHost="10.0.112.4", Community="public")` 

(2秒後看到錯誤):類型錯誤:期望的字符串或Unicode對象,NoneType發現

和值不被改變。

我該怎麼做?我應該如何使它正確?

跟蹤(請幫忙明白它的意思):

--Call-- 
> /usr/lib/python2.7/dist-packages/netsnmp/client.py(185)set() 
-> def set(self, varlist): 
(Pdb) 
> /usr/lib/python2.7/dist-packages/netsnmp/client.py(186)set() 
-> res = client_intf.set(self, varlist) 
(Pdb) 
--Call-- 
> /usr/lib/python2.7/dist-packages/netsnmp/client.py(94)__iter__() 
-> def __iter__(self): 
(Pdb) 
> /usr/lib/python2.7/dist-packages/netsnmp/client.py(95)__iter__() 
-> return iter(self.varbinds) 
(Pdb) 
--Return-- 
> /usr/lib/python2.7/dist-packages/netsnmp/client.py(95)__iter__()-><listite...c8096490> 
-> return iter(self.varbinds) 
(Pdb) 
Traceback (most recent call last): 
    File "./snmp-set.py", line 7, in <module> 
    netsnmp.snmpset(snmpcfgfile, Version=2, DestHost="10.0.112.4", Community="public") 
    File "/usr/lib/python2.7/dist-packages/netsnmp/client.py", line 228, in snmpset 
    res = sess.set(var_list) 
    File "/usr/lib/python2.7/dist-packages/netsnmp/client.py", line 187, in set 
    return res 
    File "/usr/lib/python2.7/dist-packages/netsnmp/client.py", line 187, in set 
    return res 
    File "/usr/lib/python2.7/bdb.py", line 49, in trace_dispatch 
    return self.dispatch_line(frame) 
    File "/usr/lib/python2.7/bdb.py", line 67, in dispatch_line 
    self.user_line(frame) 
    File "/usr/lib/python2.7/pdb.py", line 157, in user_line 
    if self.bp_commands(frame): 
    File "/usr/lib/python2.7/pdb.py", line 167, in bp_commands 
    if getattr(self, "currentbp", False) and \ 
TypeError: expected string or Unicode object, NoneType found  
+0

向我們展示完整的代碼。 –

+0

@ m170897017我編輯了問題。看它。在 – Dees7

+0

這個問題中有一個完整的代碼,2秒延遲看起來像請求超時。你確定'公開'應該被用作社區字符串嗎? – pajaja

回答

0

你可以嘗試從this blog post遵循建議,並分解你的OID的字符串和索引這樣:

snmpcfgfile=netsnmp.Varbind("agentBscSwFile", "0", "switch.cfg", "STRING") 

您還應該確保您可以使用「公共」社區編寫OID,通常此社區在默認出廠設置中默認爲只讀。

祝你好運,關於net-snmp python綁定的文檔充其量是參差不齊的。

相關問題