Using API via Python Using API via Python

Topic: Using API via Python

Post Using API via Python
by vier on 13 June 2024

Bash works but I cannot seem to get it to work via python. The debug output from debug is below after the python source code. Have I made any obvious errors?

#!/usr/bin/env bash

VAL=`curl -X POST{ID}/record/{RID} -H "accept: application/json" -H "API-Key: {KEY}" -d "{ \"nodeName\": \"_acme-challenge\", \"recordType\": \"TXT\", \"state\": true, \"textData\": \"DATA\" }"`
echo $VAL | python -m json.tool

{ "statusCode": 200, ... }


#!/usr/bin/env python
import requests

url = ""
hostid = {ID}
recordid = {RID}
type = "record"

url = url +"/"+ str(hostid) +"/"+ type +"/"+ str(recordid);

header = {
"accept": "application/json",
"API-Key": "{KEY}"

pd = {
"nodeName": "_acme-challenge",
"recordType": "TXT",
"state": "true",
"textData": "Python"

response =, data=pd, headers=header)


{'accept': 'application/json', 'API-Key': '{{KEY}'}
{'nodeName': '_acme-challenge', 'recordType': 'TXT', 'state': 'true', 'textData': 'Python'}{ID}/record/{RID}

DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1):
send: b'POST /v2/dns/{ID}/record/{RID} HTTP/1.1\r\nHost:\r\nUser-Agent: python-requests/2.32.1\r\nAccept-Encoding: gzip, deflate\r\naccept: application/json\r\nConnection: keep-alive\r\nAPI-Key: {KEY}\r\nContent-Length: 66\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n'
send: b'nodeName=_acme-challenge&recordType=TXT&state=true&textData=Python'
reply: 'HTTP/1.1 501 Argument Exception\r\n'
header: Date: Thu, 13 Jun 2024 18:58:25 GMT
header: Server: Dynu Web Server
header: X-Powered-By: Dynu Dynamic DNS Service
header: Cache-Control: no-store
header: Pragma: no-cache
header: Content-Length: 67
header: Content-Type: application/json; charset=UTF-8
DEBUG:urllib3.connectionpool: "POST /v2/dns/{ID}/record/{RID} HTTP/1.1" 501 67

Reply with quote | Report
25 July 2024 00:13