Return parsed objects returned from a POST request to ``path``. :param path: The path to fetch. :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 ma
(
self,
path: str,
*,
data: dict[str, Any] | bytes | IO | str | None = None,
files: dict[str, IO] | None = None,
json: dict[Any, Any] | list[Any] | None = None,
params: dict[str, str | int] | None = None,
)
| 787 | return self._objectify_request(data=data, json=json, method="PATCH", params=params, path=path) |
| 788 | |
| 789 | def post( |
| 790 | self, |
| 791 | path: str, |
| 792 | *, |
| 793 | data: dict[str, Any] | bytes | IO | str | None = None, |
| 794 | files: dict[str, IO] | None = None, |
| 795 | json: dict[Any, Any] | list[Any] | None = None, |
| 796 | params: dict[str, str | int] | None = None, |
| 797 | ) -> Any: |
| 798 | """Return parsed objects returned from a POST request to ``path``. |
| 799 | |
| 800 | :param path: The path to fetch. |
| 801 | :param data: Dictionary, bytes, or file-like object to send in the body of the |
| 802 | request (default: ``None``). |
| 803 | :param files: Dictionary, filename to file (like) object mapping (default: |
| 804 | ``None``). |
| 805 | :param json: JSON-serializable object to send in the body of the request with a |
| 806 | Content-Type header of application/json (default: ``None``). If ``json`` is |
| 807 | provided, ``data`` should not be. |
| 808 | :param params: The query parameters to add to the request (default: ``None``). |
| 809 | |
| 810 | """ |
| 811 | if json is None: |
| 812 | data = data or {} |
| 813 | |
| 814 | attempts = 3 |
| 815 | last_exception: RedditAPIException | None = None |
| 816 | while attempts > 0: |
| 817 | attempts -= 1 |
| 818 | try: |
| 819 | return self._objectify_request( |
| 820 | data=data, |
| 821 | files=files, |
| 822 | json=json, |
| 823 | method="POST", |
| 824 | params=params, |
| 825 | path=path, |
| 826 | ) |
| 827 | except RedditAPIException as exception: |
| 828 | last_exception = exception |
| 829 | seconds = self._handle_rate_limit(exception=exception) |
| 830 | if seconds is None: |
| 831 | break |
| 832 | second_string = "second" if seconds == 1 else "seconds" |
| 833 | logger.debug("Rate limit hit, sleeping for %d %s", seconds, second_string) |
| 834 | time.sleep(seconds) |
| 835 | assert last_exception is not None |
| 836 | raise last_exception |
| 837 | |
| 838 | def put( |
| 839 | self, |