Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No differentiation HEX-String and String #51

Open
gzivdo opened this issue Sep 22, 2016 · 3 comments
Open

No differentiation HEX-String and String #51

gzivdo opened this issue Sep 22, 2016 · 3 comments
Labels

Comments

@gzivdo
Copy link

gzivdo commented Sep 22, 2016

With snmpwalk I have this example output:
iso.0.8802.1.1.2.1.4.1.1.7.2520.9.1 = Hex-STRING: 31 2F 33 00
iso.0.8802.1.1.2.1.4.1.1.7.70039082.5.24 = Hex-STRING: 6C 20 56 54 93 D8
iso.0.8802.1.1.2.1.4.1.1.9.70039082.5.24 = STRING: "CISCO ATA SPA122"

With easysnmp I have unicode headache because of stupid compat module, which convert all to unicode even hex string, which is usually mac address.
Please add Hex-STRING snmp_type and return value as encode('hex') from latin1 string (not unicode string).
In this example '31 2F 33 00 ' is a normal string, but I dont see a way for now how to detect it, but what i defenetly need - preserve mac address as hex string (better non unicode).

If I use use_sprint_value=True, I have additionally double quotes, which not needed.

And integer type i want as integer, not unicode string.

@BYT3M3
Copy link

BYT3M3 commented Nov 14, 2017

I'd like to help fix this issue, because I have a certain OID I cannot set properly without the Hex-String functionality.

@burakCokyildirim
Copy link

Hello,
Is there any developments about this problem? or Any solution?

@benafischer94
Copy link

For anyone else that comes across this, while I agree the compat could use some help on OCTET STR types. A short work around that appears to be good and concise:

from easysnmp import snmp_get

OID = iso.0.8802.1.1.2.1.4.1.1.7.2520.9.1
snmp_get(OID, hostname='192.0.2.1', community='public', version=2).value.encode('latin-1')

You'll end up with a bytes object of the hex.

E.g. follow the original example if snmpget returns:
iso.0.8802.1.1.2.1.4.1.1.7.2520.9.1 = Hex-STRING: 31 2F 33 00

Then you would get:

from easysnmp import snmp_get

OID = iso.0.8802.1.1.2.1.4.1.1.7.2520.9.1
snmp_get(OID, hostname='192.0.2.1', community='public', version=2).value.encode('latin-1')

b'\x31\x2f\x33\x00'

I'm sure there was some design reason behind using latin-1 encoding originally. But it does draw a good amount of confusion, especially with beginners. And the fragmentation of SNMP in Python doesn't help much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants