Skip to content

Disable xpath escape#406

Merged
iMicknl merged 3 commits into
iMicknl:mainfrom
rhegner:enhancement/disable_escape
May 12, 2025
Merged

Disable xpath escape#406
iMicknl merged 3 commits into
iMicknl:mainfrom
rhegner:enhancement/disable_escape

Conversation

@rhegner

@rhegner rhegner commented May 11, 2025

Copy link
Copy Markdown
Contributor

I had a second problem with my "Sunrise Internet Box".

Attempting to read the value of the following xpath failed:

Device/IP/Interfaces/Interface[Alias='IP_DATA']/IPv4Addresses/IPv4Address[Alias='IP_DATA_ADDRESS']/IPAddress

Instead of the IP address I was looking for, get_value_by_xpath returned a JSON structure with lots of status information in it, but not the IP address I was looking for. Turns out that url quoting messed things up.

So I added a new parameter to the get_value_by_xpath function:

The following now returns the desired IP address as expected:

await client.get_value_by_xpath("Device/IP/Interfaces/Interface[Alias='IP_DATA']/IPv4Addresses/IPv4Address[Alias='IP_DATA_ADDRESS']/IPAddress", { "capability-flags": { "interface": True }}, False)

@rhegner rhegner requested a review from iMicknl as a code owner May 11, 2025 20:37
@rhegner

rhegner commented May 11, 2025

Copy link
Copy Markdown
Contributor Author

PS: Depending on what the original intent was for using that url quoting, a more elegant approach could be to specify the required characters as "safe characters" (instead of introducing a new parameter).

The following works fine for me too:

        actions = {
            "id": 0,
            "method": "getValue",
            "xpath": urllib.parse.quote(xpath, "/=[]'"),
            "options": options if options else {},
        }

https://docs.python.org/3/library/urllib.parse.html#urllib.parse.quote

@iMicknl

iMicknl commented May 11, 2025

Copy link
Copy Markdown
Owner

@rhegner I would prefer your second option, to not add additional parameters here :)

@rhegner

rhegner commented May 12, 2025

Copy link
Copy Markdown
Contributor Author

Yes, it's cleaner. I updated my PR.

@iMicknl iMicknl left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM!

@iMicknl iMicknl merged commit 35bc37d into iMicknl:main May 12, 2025
4 checks passed
@rhegner

rhegner commented May 25, 2025

Copy link
Copy Markdown
Contributor Author

@iMicknl do you plan to release a new version of your library with this PR included anytime soon?

@iMicknl

iMicknl commented May 25, 2025

Copy link
Copy Markdown
Owner

@iMicknl do you plan to release a new version of your library with this PR included anytime soon?

Done!

bakonyiferenc pushed a commit to bakonyiferenc/python-sagemcom-api that referenced this pull request Dec 16, 2025
I had a second problem with my "Sunrise Internet Box".

Attempting to read the value of the following xpath failed:

```
Device/IP/Interfaces/Interface[Alias='IP_DATA']/IPv4Addresses/IPv4Address[Alias='IP_DATA_ADDRESS']/IPAddress
```

Instead of the IP address I was looking for, `get_value_by_xpath`
returned a JSON structure with lots of status information in it, but not
the IP address I was looking for. Turns out that url quoting messed
things up.

So I added a new parameter to the `get_value_by_xpath` function:

The following now returns  the desired IP address as expected:
```
await client.get_value_by_xpath("Device/IP/Interfaces/Interface[Alias='IP_DATA']/IPv4Addresses/IPv4Address[Alias='IP_DATA_ADDRESS']/IPAddress", { "capability-flags": { "interface": True }}, False)
```

---------

Co-authored-by: Robert Hegner <robert.hegner@loftdynamics.com>
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

Successfully merging this pull request may close these issues.

2 participants