Skip to content

Commit d0cfad3

Browse files
committed
Handle JSONDecodeError in dynamic client discovery
#2429 When the Kubernetes API server returns a 503 Service Unavailable error with a text/plain content type (instead of application/json), the dynamic client fails with an unhandled JSONDecodeError exception while trying to parse the response as JSON.
1 parent c330b84 commit d0cfad3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kubernetes/base/dynamic/discovery.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from collections import defaultdict
2323
from abc import abstractmethod, abstractproperty
2424

25+
from json.decoder import JSONDecodeError
2526
from urllib3.exceptions import ProtocolError, MaxRetryError
2627

2728
from kubernetes import __version__
@@ -164,7 +165,8 @@ def get_resources_for_api_version(self, prefix, group, version, preferred):
164165
path = '/'.join(filter(None, [prefix, group, version]))
165166
try:
166167
resources_response = self.client.request('GET', path).resources or []
167-
except ServiceUnavailableError:
168+
except (ServiceUnavailableError, JSONDecodeError):
169+
# Handle both service unavailable errors and JSON decode errors
168170
resources_response = []
169171

170172
resources_raw = list(filter(lambda resource: '/' not in resource['name'], resources_response))

0 commit comments

Comments
 (0)