Using API via Python
Using API via Python
- Casa
- Pannello di controllo
- Forum della Comunità
- Services
- Dynamic DNS Service
- Using API via Python
- Forum della Comunità
- Using API via Python
Argomento: 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 bash
VAL=`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.tool
Reponse:
{ "statusCode": 200, ... }
======
#!/usr/bin/env python
import requests
url = "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:443
send: 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 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:https://api.dynu.com:443 "POST /v2/dns/{ID}/record/{RID} HTTP/1.1" 501 67
#!/usr/bin/env bash
VAL=`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.tool
Reponse:
{ "statusCode": 200, ... }
======
#!/usr/bin/env python
import requests
url = "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:443
send: 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 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:https://api.dynu.com:443 "POST /v2/dns/{ID}/record/{RID} HTTP/1.1" 501 67
Rispondi con citazione | Segnalare
Autore | Argomento: Using API via Python |
---|---|
vier Iscritto: 26/09/2016 |
![]() giovedì 13 giugno 2024 12:06
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 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.tool Reponse: { "statusCode": 200, ... } ====== #!/usr/bin/env python import requests url = "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:443 send: 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 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:https://api.dynu.com:443 "POST /v2/dns/{ID}/record/{RID} HTTP/1.1" 501 67 |

mercoledì 2 aprile 2025 15:49