Return the parsed JSON data returned from a request to URL. :param data: Dictionary, bytes, or file-like object to send in the body of the request (default: ``None``). :param files: Dictionary, filename to file (like) object mapping (default: ``None``).
(
self,
*,
data: dict[str, Any] | bytes | IO | str | None = None,
files: dict[str, IO] | None = None,
json: dict[Any, Any] | list[Any] | None = None,
method: str,
params: dict[str, str | int] | None = None,
path: str,
)
| 866 | return models.Redditor(self, fullname=fullname, name=name) |
| 867 | |
| 868 | def request( |
| 869 | self, |
| 870 | *, |
| 871 | data: dict[str, Any] | bytes | IO | str | None = None, |
| 872 | files: dict[str, IO] | None = None, |
| 873 | json: dict[Any, Any] | list[Any] | None = None, |
| 874 | method: str, |
| 875 | params: dict[str, str | int] | None = None, |
| 876 | path: str, |
| 877 | ) -> Any: |
| 878 | """Return the parsed JSON data returned from a request to URL. |
| 879 | |
| 880 | :param data: Dictionary, bytes, or file-like object to send in the body of the |
| 881 | request (default: ``None``). |
| 882 | :param files: Dictionary, filename to file (like) object mapping (default: |
| 883 | ``None``). |
| 884 | :param json: JSON-serializable object to send in the body of the request with a |
| 885 | Content-Type header of application/json (default: ``None``). If ``json`` is |
| 886 | provided, ``data`` should not be. |
| 887 | :param method: The HTTP method (e.g., ``"GET"``, ``"POST"``, ``"PUT"``, |
| 888 | ``"DELETE"``). |
| 889 | :param params: The query parameters to add to the request (default: ``None``). |
| 890 | :param path: The path to fetch. |
| 891 | |
| 892 | """ |
| 893 | if self.config.check_for_async: |
| 894 | self._check_for_async() |
| 895 | if data and json: |
| 896 | msg = "At most one of 'data' or 'json' is supported." |
| 897 | raise ClientException(msg) |
| 898 | assert self._core is not None |
| 899 | try: |
| 900 | return self._core.request( |
| 901 | data=data, |
| 902 | files=files, |
| 903 | json=json, |
| 904 | method=method, |
| 905 | params=params, |
| 906 | path=path, |
| 907 | ) |
| 908 | except BadRequest as exception: |
| 909 | error_data: dict[str, Any] |
| 910 | try: |
| 911 | error_data = exception.response.json() |
| 912 | except ValueError: |
| 913 | if exception.response.text: |
| 914 | error_data = {"reason": exception.response.text} |
| 915 | else: |
| 916 | raise exception from None |
| 917 | if set(error_data) == {"error", "message"}: |
| 918 | raise |
| 919 | explanation = error_data.get("explanation") |
| 920 | if "fields" in error_data: |
| 921 | assert len(error_data["fields"]) == 1 |
| 922 | field = error_data["fields"][0] |
| 923 | else: |
| 924 | field = None |
| 925 | raise RedditAPIException( |