fix: missing Content-Type
-header in API request
This commit is contained in:
parent
4f1547a61b
commit
4d484ebd60
1 changed files with 19 additions and 8 deletions
25
dnsupdate.py
25
dnsupdate.py
|
@ -3,7 +3,7 @@
|
|||
"""A script which sends a Dynamic DNS update to the Ionos API."""
|
||||
|
||||
from pathlib import Path
|
||||
import requests
|
||||
import json, requests
|
||||
from yaml import load
|
||||
try:
|
||||
from yaml import CLoader as Loader
|
||||
|
@ -70,15 +70,22 @@ def main():
|
|||
apikey = f"{apikey_prefix}.{apikey_secret}"
|
||||
domains = config["domains"]
|
||||
description = config["description"] if "description" in config else "Dynamic DNS update."
|
||||
payload = json.dumps(
|
||||
{
|
||||
"domains": domains,
|
||||
"description": description,
|
||||
},
|
||||
indent=2,
|
||||
)
|
||||
|
||||
# Make an API call to retrieve the DNS update URL
|
||||
response = requests.post(
|
||||
_API_ENDPOINT_URL,
|
||||
headers={"X-API-Key": apikey},
|
||||
data={
|
||||
"domains": domains,
|
||||
"description": description,
|
||||
}
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"X-API-Key": apikey,
|
||||
},
|
||||
data=payload
|
||||
)
|
||||
|
||||
if not response.status_code == 200:
|
||||
|
@ -90,8 +97,12 @@ def main():
|
|||
f"API request failed and returned: {error_message}"
|
||||
)
|
||||
|
||||
try:
|
||||
update_url = response.json()["updateUrl"]
|
||||
print(update_url) # DEBUG
|
||||
except requests.exceptions.JSONDecodeError as e:
|
||||
raise RuntimeError(
|
||||
"Failed to parse update URL from API response."
|
||||
) from e
|
||||
|
||||
# Send a dynamic DNS update using the retrieved update URL
|
||||
response = requests.get(update_url)
|
||||
|
|
Loading…
Add table
Reference in a new issue