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

Callling /control/parental/enable failing with only content-type application/json is allowed #795

Closed
hastarin opened this issue Aug 6, 2023 · 4 comments

Comments

@hastarin
Copy link
Contributor

hastarin commented Aug 6, 2023

Problem/Motivation

I'm using the AdGuard Home addon in Home Assistant and believe I've traced a bug I'm having to the code in this repository.

Specifically, the call to /control/parental/enable is failing.

Expected behavior

Should be able to enable the parental filtering via the API wrapper.

Actual behavior

Throws an error with: only content-type application/json is allowed.

Steps to reproduce

  • pip install adguardhome
  • Temporarily configure AdGuard Home Addon in HA to leave_front_door_open and set a port (eg 3001) for the Web interface
    image
  • Edit the following and change the IP/port to suit your AdGuard Home installation
"""Asynchronous Python client for the AdGuard Home API."""

import asyncio

from adguardhome import AdGuardHome


async def main():
    """Show example how to get status of your AdGuard Home instance."""
    async with AdGuardHome(host="192.168.1.2", port="3001", tls=True, verify_ssl=False) as adguard:
        version = await adguard.version()
        print("AdGuard version:", version)

        await adguard.parental.disable()

        active = await adguard.parental.enabled()
        active = "Yes" if active else "No"
        print("Parental control enabled?", active)

        await adguard.parental.enable()
        active = await adguard.parental.enabled()
        active = "Yes" if active else "No"
        print("Parental control enabled?", active)


if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())
  • python3 adguard_test.py

Proposed changes

It appears the AdGuard Home API now enforces a "Content-Type: application/json" for the API when a body is present. The request to /control/parental/enable is adding a body but it's not JSON.

From what I can tell from https://github.com/AdguardTeam/AdGuardHome/blob/master/openapi/openapi.yaml the endpoint doesn't actually expect a body.

The fix is to simply remove the data argument on line 36 of parental.py.

hastarin added a commit to hastarin/python-adguardhome that referenced this issue Aug 6, 2023
@github-actions
Copy link

github-actions bot commented Sep 5, 2023

There hasn't been any activity on this issue recently, so we clean up some of the older and inactive issues.
Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by leaving a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thanks!

@github-actions github-actions bot added the stale There has not been activity on this issue or PR for quite some time. label Sep 5, 2023
@hastarin
Copy link
Contributor Author

hastarin commented Sep 5, 2023 via email

@github-actions github-actions bot removed the stale There has not been activity on this issue or PR for quite some time. label Sep 6, 2023
@stamandr
Copy link

Many of us have been waiting a long time for this fix....

frenck pushed a commit to hastarin/python-adguardhome that referenced this issue Oct 20, 2023
@frenck
Copy link
Owner

frenck commented Oct 23, 2023

fixed in #796

@frenck frenck closed this as completed Oct 23, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants