Unbound API

Started by hibby50, May 04, 2022, 04:53:33 PM

Previous topic - Next topic
Hi All,

I'm looking for some help using the API to disable adblock in unbound. When I run the below script, it outputs ok, but the setting never changes. Is there something else I need to execute to apply the setting or something? I looked at the network console in my browser and though I had it all covered. I will post the code and output below. Any help would be appreciated.


# import libraries
import json
import requests

# define endpoint and credentials
api_key = '<redacted>'
api_secret = '<redacted>'
url = 'https://hibrouter/api/unbound/settings/set'
setting = '{"unbound":{"dnsbl":{"enabled":"0","type":"aa,ag,sa,st","lists":"","whitelists":""},"miscellaneous":{"privatedomain":"","insecuredomain":""}}}'
apply_url = "https://hibrouter/api/unbound/service/dnsbl"

# request data
r = requests.post(url,
                 verify=False,
                 data=setting,
                 auth=(api_key, api_secret))

if r.status_code == 200:
    response = json.loads(r.text)
    print(str(r.text))
else:
    print ('Connection / Authentication issue, response received:')
    print (r.text)

r = requests.post(apply_url,
                 verify=False,
                 auth=(api_key, api_secret))

if r.status_code == 200:
    response = json.loads(r.text)
    print(str(r.text))
else:
    print ('Connection / Authentication issue, response received:')
    print (r.text)



╰─ python3 adblock-api.py
/usr/lib/python3.8/site-packages/urllib3/connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'hibrouter'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
{"result":"saved"}
/usr/lib/python3.8/site-packages/urllib3/connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'hibrouter'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
{"status":"OK\n\n"}

wild speculation. Restart the service (like normally you have to press "apply/save")