From 42db0c03ac0e903c937a10c97ff08b5e4dc3285d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Szulc?= Date: Fri, 23 Feb 2024 12:53:32 +0100 Subject: [PATCH 1/2] Fix error when decoding response from DNSaaS --- src/ralph/dns/dnsaas.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ralph/dns/dnsaas.py b/src/ralph/dns/dnsaas.py index f8c1fbab54..a926fbae86 100644 --- a/src/ralph/dns/dnsaas.py +++ b/src/ralph/dns/dnsaas.py @@ -5,7 +5,6 @@ from functools import wraps from typing import List, Optional, Tuple, Union from urllib.parse import parse_qs, urlencode, urljoin, urlsplit - import requests from dj.choices import Choices from django.conf import settings @@ -184,7 +183,7 @@ def update_dns_record(self, record: dict) -> Optional[dict]: return response_data @staticmethod - def _response2result(response: requests.Response) -> Union[dict, list]: + def _response2result(response: requests.Response) -> Union[dict, list, None]: if response.status_code == 500: logger.error('Internal Server Error from DNSAAS: %s', response.content) @@ -192,7 +191,10 @@ def _response2result(response: requests.Response) -> Union[dict, list]: 'non_field_errors': ['Internal Server Error from DNSAAS'] } elif response.status_code not in (202, 204): - return response.json() + try: + return response.json() + except ValueError: + pass def create_dns_record(self, record: dict, service=None) -> Optional[dict]: """ From a7c2bc45b3ef6e33c4a6c5bd30683c5b3864eea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Szulc?= Date: Fri, 23 Feb 2024 13:00:39 +0100 Subject: [PATCH 2/2] Fix flake8 --- src/ralph/dns/dnsaas.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ralph/dns/dnsaas.py b/src/ralph/dns/dnsaas.py index a926fbae86..0bc8a1d643 100644 --- a/src/ralph/dns/dnsaas.py +++ b/src/ralph/dns/dnsaas.py @@ -183,7 +183,9 @@ def update_dns_record(self, record: dict) -> Optional[dict]: return response_data @staticmethod - def _response2result(response: requests.Response) -> Union[dict, list, None]: + def _response2result( + response: requests.Response + ) -> Union[dict, list, None]: if response.status_code == 500: logger.error('Internal Server Error from DNSAAS: %s', response.content)