#!/usr/bin/env python # NOTE: manual tests. These will disappear after being integrated in test_api.py and eventual friends. # import requests # unused for now from pdnsapi import PdnsRestAdapter # import json import datetime api = PdnsRestAdapter('localhost:8081/', 'pdns-supersecret') # test1.nhn.no zone must exist for this to work output = api.get('servers/localhost/zones/test1.nhn.no') print("GET zones/test1.nhn.no:") print(f"{output}") print() # NOTE: this one puts two records into powerdns input = { "rrsets": [ { "name": "test.test1.nhn.no.", "type": "TXT", "ttl": 60, "changetype": "REPLACE", "records": [ { "content": f'"tester tekst-record {datetime.datetime.now().strftime('%d.%m.%Y %H:%M')}"', "disabled": False, "name": "test.test1.nhn.no", "ttl": 60, "type": "TXT" } ] }, { "name": "testa.test1.nhn.no.", "type": "A", "ttl": 60, "changetype": "REPLACE", "records": [ { "content": "127.0.0.1", "disabled": False, "name": "test.test1.nhn.no", "ttl": 60, "type": "A" } ] } ] } api.patch('servers/localhost/zones/test1.nhn.no', {}, input) print("PATCH doesn't have output per now, should it? If you can see this it worked.") # 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 # 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)