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

Toml decoder is trying to convert IP address string to float #414

Open
arnab00 opened this issue Mar 10, 2023 · 3 comments
Open

Toml decoder is trying to convert IP address string to float #414

arnab00 opened this issue Mar 10, 2023 · 3 comments

Comments

@arnab00
Copy link

arnab00 commented Mar 10, 2023

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)
@Vedant-code
Copy link

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"

@arnab00
Copy link
Author

arnab00 commented Mar 10, 2023

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?

@Kroppeb
Copy link

Kroppeb commented Mar 11, 2024

This is an ini file, not a toml file

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

No branches or pull requests

3 participants