openpyn-nordvpn icon indicating copy to clipboard operation
openpyn-nordvpn copied to clipboard

Locale with comma as decimal point causes failure in ping tests

Open RobinR1 opened this issue 5 years ago • 2 comments

I have a debian machine with locate set to dutch (NL-nl or NL-be) which uses a comma as decimal point. The installed ping version is: inetutils (2:1.9.4-2) openpyn fails with this output:

# /usr/local/bin/openpyn be --p2p
According to NordVPN, Least Busy 10 Servers, In BE With 'Load' less than 70 Which Support OPENVPN-UDP , p2p =  True are : [['be24', 4], ['be41', 5], ['be30', 6], ['be37', 7], ['be64', 7], ['be12', 8], ['be13', 8], ['be47', 8], ['be18', 9], ['be19', 9]] 

Your 'ping' command doesn't support '-i' or '-n', falling back to wait of 1 second between pings, pings will be slow

Traceback (most recent call last):
  File "/usr/local/bin/openpyn", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.5/dist-packages/openpyn/openpyn.py", line 130, in main
    args.skip_dns_patch, args.silent, args.nvram, args.openvpn_options)
  File "/usr/local/lib/python3.5/dist-packages/openpyn/openpyn.py", line 307, in run
    pinged_servers_list = ping_servers(better_servers_list, pings)
  File "/usr/local/lib/python3.5/dist-packages/openpyn/openpyn.py", line 453, in ping_servers
    ping_list = list(map(float, ping_list))
ValueError: could not convert string to float: '16,076'

I found the error about the lack of -i and -n support was caused due to the fact that you call ping as such: ping -n -i .2 -c 2 8.8.8.8 where it should be called as ping -n -i ,2 -c 2 8.8.8.8

After that the script fails to interpret the ping output due to the comma's in the ping values.

As a workaround I removed inetutils (2:1.9.4-2) and installed iputils-ping (3:20161105-1) instead which didn't seem to have any locale adaptations and thus works with the script as intended.

So I think it is best to also check for the decimal point character and if ping is locale-translated or not to catch this kind of errors ?

RobinR1 avatar Jul 17 '18 13:07 RobinR1

This seems like a very unique scenario as I believe most distros have iputils and checking for it wouldn't be a one liner. For example the issue here was not just that ping -n -i .2 -c 2 8.8.8.8 didn't run. That is dealt with but then pyhton can't directly convert "16,076" to float. unless it's not as rare case as I think it is, it's not worth it.

jotyGill avatar Sep 19 '18 02:09 jotyGill

Well actually ping -n -i .2 -c 2 8.8.8.8 didn't run when it was the inetutils versions, hence the error about not supporting -i or -n. Manually running that command revealed that it expected a decimal comma instead of a point for the '.2' value on my system. openpyn then falls back to the 'wait of 1 second'-method and then here it fails to interpret the float with decimal comma returned by the inetutils version of ping in dutch locale.

I encountered this problem on a default install of OSMC on an embedded device. OSMC is a debian based distribution for running a (Kodi) mediacenter, optimized to run on embedded devices such as Raspberry Pi's or their own device Vero4K.. So I assume this is not that rare of a case on embedded devices as probably more embedded device-oriented distro's will use inetutils...

For me the problem is resolved by replacing inetutils by iputils-ping, but in theory inetutils should suffice as it does support the -n and -i parameters (and probably does in US locale). So up to you if you want to handle that in openpyn..but at least, now you know about this problem :-)

RobinR1 avatar Oct 02 '18 10:10 RobinR1