|
25 | 25 | RequestUriTooLongException, |
26 | 26 | ) |
27 | 27 |
|
28 | | - |
29 | 28 | try: # pragma: no cover |
30 | 29 | from collections.abc import MutableMapping, MutableSequence |
31 | 30 | except ImportError: # pragma: no cover |
@@ -111,7 +110,9 @@ def _make_request(self): |
111 | 110 | if self.product == "iris-investigate" and "irisql" in self.kwargs: |
112 | 111 | irisql_query = self.kwargs["irisql"] |
113 | 112 | auth_keys = {"api_username", "timestamp", "signature", "api_key"} |
114 | | - query_params = {k: v for k, v in self.kwargs.items() if k != "irisql" and k not in auth_keys} |
| 113 | + query_params = { |
| 114 | + k: v for k, v in self.kwargs.items() if k != "irisql" and k not in auth_keys |
| 115 | + } |
115 | 116 | query_params.update(self.api.extra_request_params) |
116 | 117 | return session.post( |
117 | 118 | url=self.url, |
@@ -164,21 +165,27 @@ def data(self): |
164 | 165 | self._data = results.json() |
165 | 166 | else: |
166 | 167 | self._data = results.text |
167 | | - |
168 | 168 | self.check_limit_exceeded() |
169 | 169 |
|
170 | 170 | return self._data |
171 | 171 |
|
172 | 172 | def check_limit_exceeded(self): |
173 | 173 | limit_exceeded, reason = False, "" |
| 174 | + |
174 | 175 | if isinstance(self._data, dict) and ( |
175 | 176 | "response" in self._data |
176 | 177 | and "limit_exceeded" in self._data["response"] |
177 | 178 | and self._data["response"]["limit_exceeded"] is True |
178 | 179 | ): |
179 | 180 | limit_exceeded, reason = True, self._data["response"]["message"] |
180 | 181 | elif "response" in self._data and "limit_exceeded" in self._data: |
181 | | - limit_exceeded = True |
| 182 | + # check for xml format, and return the actual error message |
| 183 | + if self.kwargs.get("format") == "xml" and isinstance(self._data, str): |
| 184 | + if re.search(r"<limit_exceeded>1</limit_exceeded>", self._data): |
| 185 | + msg = re.search(r"<message>(.*?)</message>", self._data) |
| 186 | + limit_exceeded, reason = True, msg.group(1) if msg else "" |
| 187 | + else: |
| 188 | + limit_exceeded = True |
182 | 189 |
|
183 | 190 | if limit_exceeded: |
184 | 191 | raise ServiceException(503, f"Limit Exceeded {reason}") |
@@ -354,9 +361,7 @@ def html(self): |
354 | 361 | ) |
355 | 362 |
|
356 | 363 | def as_list(self): |
357 | | - return "\n".join( |
358 | | - [json.dumps(item, indent=4, separators=(",", ": ")) for item in self._items()] |
359 | | - ) |
| 364 | + return "\n".join([json.dumps(item, indent=4, separators=(",", ": ")) for item in self._items()]) |
360 | 365 |
|
361 | 366 | def __str__(self): |
362 | 367 | return str( |
|
0 commit comments