Skip to content

Commit 8cb5012

Browse files
fixed the api endpoint
1 parent c04cadf commit 8cb5012

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

ns1/rest/zones.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,28 @@ def get_zonefile_export(self, zone, callback=None, errback=None):
224224
:param str zone: zone name
225225
:return: zone file content as string
226226
"""
227-
return self._make_request(
228-
"GET",
229-
f"{self.ROOT}/{zone}/export",
230-
callback=callback,
231-
errback=errback,
232-
)
227+
# Note: This endpoint returns raw zone file text, not JSON
228+
# The transport layer will try to parse it as JSON and fail
229+
# We catch that exception and extract the raw body text
230+
from ns1.rest.errors import ResourceException
231+
232+
try:
233+
return self._make_request(
234+
"GET",
235+
f"export/zonefile/{zone}",
236+
callback=callback,
237+
errback=errback,
238+
)
239+
except ResourceException as e:
240+
# If it's about invalid JSON, that's expected - extract the body
241+
if "invalid json in response" in str(e):
242+
# The body is the third argument in ResourceException
243+
if hasattr(e, 'args') and len(e.args) >= 3:
244+
body = e.args[2]
245+
if callback:
246+
return callback(body)
247+
return body
248+
raise
233249

234250

235251
# successive pages just extend the list of zones

tests/unit/test_zone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def test_rest_zone_buildbody(zones_config):
254254

255255

256256
@pytest.mark.parametrize(
257-
"zone, url", [("test.zone", "zones/test.zone/export")]
257+
"zone, url", [("test.zone", "export/zonefile/test.zone")]
258258
)
259259
def test_rest_zone_get_zonefile_export(zones_config, zone, url):
260260
z = ns1.rest.zones.Zones(zones_config)

0 commit comments

Comments
 (0)