(self)
| 38 | return json.loads(self.text(encoding=self._get_encoding())) |
| 39 | |
| 40 | def _get_encoding(self) -> str: |
| 41 | # Try to infer encoding from headers; default to utf-8 |
| 42 | ctype = self.headers.get("content-type", "") |
| 43 | # Example: application/json; charset=utf-8 |
| 44 | for part in ctype.split(";"): |
| 45 | p = part.strip() |
| 46 | if p.lower().startswith("charset="): |
| 47 | return p.split("=", 1)[1].strip() or "utf-8" |
| 48 | return "utf-8" |
| 49 | |
| 50 | |
| 51 | class HttpError(Exception): |