简体   繁体   中英

Net-SNMP returns HexString and then just String (Eclipse and Pydev)

I am doing an snmpget using Net-SNMP. Specifically I am sending a command via os.popen("etc"). The value returned is a Hex-string separated by spaces, something like this : "A0 f0 D0". The returned value comes sometimes in the form :"Hex-String: A0 f0 D0.." but sometimes comes in the form "String:\\xA0\\xf0\\xD0" where, as you can see, the spaces are filled with "\\x". Does anyone have an idea as to why this might be happening? I would prefer it if the returned value was the HEX-String with spaces, not \\x.

I should note that I am using Eclipse with Pydev. I then ran the same code in pyscripter and got back my Hex-String value. I ran it again in Pyscripter and then the \\x's returned. Is this something to do with an unclosed pipe?

I should also mention that the data I am getting back is bad in another sense. The Hex-String with spaces returns proper data values, but the String with \\xs returns values that are not correct.

I have used Wireshark and it looks like the get request is exactly the same as one sent from the MIB. The MIB request returns the correct data, while the Eclipse request still returns bad data.

PyDev does one thing differently, which is setting: sys.setdefaultencoding(encoding) with the encoding of the java console (so that if you print unicode to the console it won't fail saying that the unicode doesn't decode as ascii). To see if this is your problem, you can go to eclipse\\plugins\\org.python.pydev\\PySrc\\pydev_sitecustomize\\sitecustomize.py and comment the line which does: sys.setdefaultencoding(encoding)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM