fix: missing Content-Type-header in API request

This commit is contained in:
Julian Lobbes 2022-09-03 01:26:06 +02:00
parent 4f1547a61b
commit 4d484ebd60

View file

@ -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)