toml icon indicating copy to clipboard operation
toml copied to clipboard

Toml decoder is trying to convert IP address string to float

Open arnab00 opened this issue 1 year ago • 3 comments

Toml decoder is trying to convert IP address string to float. It should detect first if it's a number or not.

This is a conf file

#
# Use this configuration with WireGuard client
#
[Interface]
Address = 10.14.0.2/16
PrivateKey = <insert_your_private_key_here>
DNS = 100.252.123.123, 100.124.123.92
[Peer]
PublicKey = <insert_your_public_key_here>
AllowedIPs = 0.0.0.0/0
Endpoint = 100.90.123.123:51820

Code

import toml
data = toml.load("my-kul.prod.company.com.conf") 

Exception

Traceback (most recent call last):
  File "C:\Users\gx\AppData\Roaming\Python\Python38\site-packages\toml\decoder.py", line 511, in loads
    ret = decoder.load_line(line, currentlevel, multikey,
  File "C:\Users\gx\AppData\Roaming\Python\Python38\site-packages\toml\decoder.py", line 778, in load_line
    value, vtype = self.load_value(pair[1], strictly_valid)
  File "C:\Users\gx\AppData\Roaming\Python\Python38\site-packages\toml\decoder.py", line 912, in load_value
    v = float(v)
ValueError: could not convert string to float: '10.14.0.2/16'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "addpvkey.py", line 2, in <module>
    data = toml.load("my-kul.prod.surfshark.com.conf")
  File "C:\Users\gx\AppData\Roaming\Python\Python38\site-packages\toml\decoder.py", line 134, in load
    return loads(ffile.read(), _dict, decoder)
  File "C:\Users\gx\AppData\Roaming\Python\Python38\site-packages\toml\decoder.py", line 514, in loads
    raise TomlDecodeError(str(err), original, pos)
toml.decoder.TomlDecodeError: could not convert string to float: '10.14.0.2/16' (line 5 column 1 char 63)

arnab00 avatar Mar 10 '23 15:03 arnab00

Update the conf file

[Interface]
Address = "10.14.0.2/16"
PrivateKey = "<insert_your_private_key_here>"
DNS = ["100.252.123.123", "100.124.123.92"]

[Peer]
PublicKey = "<insert_your_public_key_here>"
AllowedIPs = "0.0.0.0/0"
Endpoint = "100.90.123.123:51820"

Vedant-code avatar Mar 10 '23 15:03 Vedant-code

Update the conf file

[Interface]
Address = "10.14.0.2/16"
PrivateKey = "<insert_your_private_key_here>"
DNS = ["100.252.123.123", "100.124.123.92"]

[Peer]
PublicKey = "<insert_your_public_key_here>"
AllowedIPs = "0.0.0.0/0"
Endpoint = "100.90.123.123:51820"

Can't do that it will break wireguard config file. My python script will read the file and add user chosen private key programmatically. Does any toml library support string format only decoder?

arnab00 avatar Mar 10 '23 16:03 arnab00

This is an ini file, not a toml file

Kroppeb avatar Mar 11 '24 18:03 Kroppeb