vyos-contrib / pyvyos

Python SDK for interacting with VyOS API
MIT License
10 stars 5 forks source link

New release and pip package update #8

Closed rico132 closed 2 months ago

rico132 commented 3 months ago

Hello @robertoberto, hello @xTITUSMAXIMUSX,

In the latest release (v0.2.1) and the main branch the function

device.config_file_save()

produces an error:

Traceback (most recent call last):
  File "script.py", line 62, in <module>
    device.config_file_save()
  File "script/.venv/lib/python3.12/site-packages/pyvyos/device.py", line 321, in config_file_save
    return self._api_request(command="config-file", op='save', file=file, method="POST")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "script/.venv/lib/python3.12/site-packages/pyvyos/device.py", line 163, in _api_request
    payload = self._get_payload(op, path=path, file=file, url=url, name=name)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "script/.venv/lib/python3.12/site-packages/pyvyos/device.py", line 111, in _get_payload
    if isinstance(path[0], list):  # Handling multiple paths
                  ~~~~^^^
IndexError: list index out of range

In my opinion, this bug should be fixed with this PR https://github.com/robertoberto/pyvyos/pull/3 But it turns out the check for an empty list is missing in the main branch AND the latest release

Updating the pip package after you release a new version would also be nice.

xTITUSMAXIMUSX commented 3 months ago

Can you provide the code you used for device.config_file_save()? It is pretty strange that it was looking for a path because the command is supposed to be used like device.config_file_save(file="/config/test300.config")

rico132 commented 2 months ago

The problem is that something went wrong after your PR got merged. Maybe someone force pushed after the merge? I do not know, I am not great with git either. But to answer your question I am using it without any parameters like it is described in the readme: https://github.com/robertoberto/pyvyos/blob/main/README.md#configure-then-save

Because some of your code is missing in the release and main branch, the empty list check is also missing. Path is an empty list as default in the _get_payload function and path[0] will run into an IndexError without the empty list check.

rico132 commented 2 months ago

@xTITUSMAXIMUSX

I think there will be no fast solution, so, if anyone has the same problem, the workaround is to install it like this:

pip install git+https://github.com/robertoberto/pyvyos.git@8ae0b4f237eb20d9ad9f511154df8eb554bde398

This is the merge commit before the code disappears from the main branch.

robertoberto commented 2 months ago

Done, thank you for waiting

https://pypi.org/project/pyvyos/

updated

rico132 commented 2 months ago

Unfortunately, this does not fix anything.

The code is still missing a check here.

You are accessing path even though it is an empty array. Therefore, I am still getting the error shown above.

I do not know what happened after 8ae0b4f237eb20d9ad9f511154df8eb554bde398, but the code does not contain the check anymore.