 Using API via Python
 Using API via Python
                 Using API via Python
  Using API via Python
                - Home
- Control Panel
- Community Forum
- Services
- Dynamic DNS Service
- Using API via Python
- Community Forum
- Using API via Python
Topic: Using API via Python
                                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 bashVAL=`curl -X POST https://api.dynu.com/v2/dns/{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.toolReponse:{ "statusCode": 200, ... }======#!/usr/bin/env python import requestsurl = "https://api.dynu.com/v2/dns"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 = requests.post(url, data=pd, headers=header)Response:{'accept': 'application/json', 'API-Key': '{{KEY}'}{'nodeName': '_acme-challenge', 'recordType': 'TXT', 'state': 'true', 'textData': 'Python'}https://api.dynu.com/v2/dns/{ID}/record/{RID}DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.dynu.com:443send: b'POST /v2/dns/{ID}/record/{RID} HTTP/1.1\r\nHost: api.dynu.com\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 GMTheader: Server: Dynu Web Serverheader: X-Powered-By: Dynu Dynamic DNS Serviceheader: Cache-Control: no-storeheader: Pragma: no-cacheheader: Content-Length: 67header: Content-Type: application/json; charset=UTF-8DEBUG:urllib3.connectionpool:https://api.dynu.com:443 "POST /v2/dns/{ID}/record/{RID} HTTP/1.1" 501 67
                                
                            
                            
                            
                        Reply with quote | Report
| Author | Topic: Using API via Python | 
|---|---|
| vier Joined: 9/26/2016 |  Using API via Python Thursday, June 13, 2024 12:06 PM 
                                    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 bashVAL=`curl -X POST https://api.dynu.com/v2/dns/{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.toolReponse:{ "statusCode": 200, ... }======#!/usr/bin/env python import requestsurl = "https://api.dynu.com/v2/dns"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 = requests.post(url, data=pd, headers=header)Response:{'accept': 'application/json', 'API-Key': '{{KEY}'}{'nodeName': '_acme-challenge', 'recordType': 'TXT', 'state': 'true', 'textData': 'Python'}https://api.dynu.com/v2/dns/{ID}/record/{RID}DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.dynu.com:443send: b'POST /v2/dns/{ID}/record/{RID} HTTP/1.1\r\nHost: api.dynu.com\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 GMTheader: Server: Dynu Web Serverheader: X-Powered-By: Dynu Dynamic DNS Serviceheader: Cache-Control: no-storeheader: Pragma: no-cacheheader: Content-Length: 67header: Content-Type: application/json; charset=UTF-8DEBUG:urllib3.connectionpool:https://api.dynu.com:443 "POST /v2/dns/{ID}/record/{RID} HTTP/1.1" 501 67
                                    
                                 | 
 It is currently Friday, October 31, 2025 5:28 AM US Mountain Standard Time
 It is currently Friday, October 31, 2025 5:28 AM US Mountain Standard Time
        
            Friday, October 31, 2025 5:28 AM
        
    
 
  
  
 