简体   繁体   English

Net-SNMP返回HexString,然后返回String(Eclipse和Pydev)

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

I am doing an snmpget using Net-SNMP. 我正在使用Net-SNMP做一个snmpget。 Specifically I am sending a command via os.popen("etc"). 具体来说,我通过os.popen(“ etc”)发送命令。 The value returned is a Hex-string separated by spaces, something like this : "A0 f0 D0". 返回的值是一个用空格分隔的十六进制字符串,例如:“ 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". 返回的值有时采用以下形式:“十六进制字符串:A0 f0 D0 ..”,但有时采用以下形式:“ String:\\ xA0 \\ xf0 \\ xD0”,如您所见,其中的空格用“ \\ 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. 如果返回值是带空格的HEX-String,而不是\\ x,我希望使用它。

I should note that I am using Eclipse with Pydev. 我应该注意,我将Eclipse与Pydev一起使用。 I then ran the same code in pyscripter and got back my Hex-String value. 然后,我在pyscripter中运行了相同的代码,并返回了我的十六进制字符串值。 I ran it again in Pyscripter and then the \\x's returned. 我再次在Pyscripter中运行它,然后返回了\\ x。 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. 带空格的十六进制字符串返回正确的数据值,但是带\\ xs的字符串返回不正确的值。

I have used Wireshark and it looks like the get request is exactly the same as one sent from the MIB. 我使用了Wireshark,看起来get请求与从MIB发送的请求完全相同。 The MIB request returns the correct data, while the Eclipse request still returns bad data. MIB请求返回正确的数据,而Eclipse请求仍然返回错误的数据。

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). PyDev做了另一件事,那就是设置:sys.setdefaultencoding(encoding)和Java控制台的编码(这样,如果您将unicode打印到控制台,它不会失败,因为unicode不会解码为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) 要查看这是否是您的问题,可以转到eclipse \\ plugins \\ org.python.pydev \\ PySrc \\ pydev_sitecustomize \\ sitecustomize.py并注释以下行:sys.setdefaultencoding(encoding)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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