pdns_dnssec/testapi.py

40 lines
2.0 KiB
Python

#!/usr/bin/env python
# import requests # unused for now
from pdnsapi import PdnsRestAdapter
api = PdnsRestAdapter('localhost:8081/', 'pdns-supersecret')
output = api.get('servers/localhost/zones/test1.nhn.no')
print(f"{output}")
# NOTE: doesn't work yet. Maybe wrong arguments?
# api.post('servers/localhost/zones/test1.nhn.no/test.txt', {'type': 'A'}, {'type': 'A'})
# copy of error message:
# Traceback (most recent call last):
# File "/home/michael/projects/pdns_dnssec/.venv/lib/python3.12/site-packages/requests/models.py", line 974, in json
# return complexjson.loads(self.text, **kwargs)
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# File "/home/michael/.local/share/uv/python/cpython-3.12.9-linux-x86_64-gnu/lib/python3.12/json/__init__.py", line 346, in loads
# return _default_decoder.decode(s)
# ^^^^^^^^^^^^^^^^^^^^^^^^^^
# File "/home/michael/.local/share/uv/python/cpython-3.12.9-linux-x86_64-gnu/lib/python3.12/json/decoder.py", line 338, in decode
# obj, end = self.raw_decode(s, idx=_w(s, 0).end())
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# File "/home/michael/.local/share/uv/python/cpython-3.12.9-linux-x86_64-gnu/lib/python3.12/json/decoder.py", line 356, in raw_decode
# raise JSONDecodeError("Expecting value", s, err.value) from None
# json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
#
# During handling of the above exception, another exception occurred:
#
# Traceback (most recent call last):
# File "/home/michael/projects/pdns_dnssec/testapi.py", line 11, in <module>
# api.post('servers/localhost/zones/test1.nhn.no/test.txt', {'type': 'A'}, {'type': 'A'})
# File "/home/michael/projects/pdns_dnssec/pdnsapi/__init__.py", line 25, in post
# data_out = response.json()
# ^^^^^^^^^^^^^^^
# File "/home/michael/projects/pdns_dnssec/.venv/lib/python3.12/site-packages/requests/models.py", line 978, in json
# raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
# requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)