title: SNMP SET request using Python
body: <p>I need to controle a simple device via SNMP using Python 3.7 just to get it "ON" (1) and "OFF" (0). In the device manual, in the MIB information, there is a list of OID for each command (ex : GET output statue : 1.3.6........).</p>
  
  <p>I manage to have the GET request working as I like (source : <a href="http://snmplabs.com/pysnmp/examples/hlapi/asyncore/sync/manager/cmdgen/snmp-versions.html" rel="nofollow noreferrer">http://snmplabs.com/pysnmp/examples/hlapi/asyncore/sync/manager/cmdgen/snmp-versions.html</a>) :</p>
  
  <pre><code>from pysnmp.hlapi import *
  
      g = getCmd(SnmpEngine()
                , CommunityData('public', mpModel=1)
                , hlapi.UdpTransportTarget(('DEVICE IP', 161))
                , ContextData()
                , ObjectType(ObjectIdentity('GET OID given by the device manual')))
  
      errorIndication, errorStatus, errorIndex, varBinds = next(g)
  
      for varBind in varBinds:
          print(' = '.join([x.prettyPrint() for x in varBind]))
  </code></pre>
  
  <p>However when I try to use SET the same way : (source : <a href="http://snmplabs.com/pysnmp/examples/hlapi/asyncore/sync/manager/cmdgen/modifying-variables.html" rel="nofollow noreferrer">http://snmplabs.com/pysnmp/examples/hlapi/asyncore/sync/manager/cmdgen/modifying-variables.html</a>)</p>
  
  <pre><code>from pysnmp.hlapi import *
  g = setCmd(SnmpEngine()
             , CommunityData('public', mpModel=1)
             , hlapi.UdpTransportTarget(('DEVICE IP', 161))
             , ContextData()
             , ObjectType(ObjectIdentity('SET OID given by the device manual, which is the same as the GET'), '1') #1 = new value
             )
  
  errorIndication, errorStatus, errorIndex, varBinds = next(g)
  
  print(errorIndication, varBinds)
  </code></pre>
  
  <p>I get the following error : </p>
  
  <pre><code>MibNotFoundError: SET OID compilation error(s): missingcaused by &lt;class 'pysnmp.smi.error.MibNotFoundError'&gt;: MIB file "SET OID.py[co]" not found in search path (DirMibSource('/home/username/anaconda3/lib/python3.7/site-packages/pysnmp/smi/mibs'), DirMibSource('/home/username/anaconda3/lib/python3.7/site-packages/pysnmp/smi/mibs/instances'), DirMibSource('pysnmp_mibs'), DirMibSource('/home/username/.pysnmp/mibs'))
  </code></pre>
  
  <p>I don't understand why it works without problem in one case and not in the other. In the device manual the instruction is the same as GET but there is STRING 0 or 1 at the end, I guess I'm missing something here but I can't found how to write it.</p>
  
  <p>I just want to give this very simple instruction, if someone has an easy answer or alternative.</p>
  
  <p>Thank you very much</p>
  
  <p>P.S. : I also tried this tutorial (<a href="https://www.ictshore.com/sdn/python-snmp-tutorial/" rel="nofollow noreferrer">https://www.ictshore.com/sdn/python-snmp-tutorial/</a>) which make it's own functions, and again GET works but not SET. I got that my OID is not Object-TYPE.</p>