You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously, if you called subreddit.random() on a subreddit which didn't support it, praw would simply return a None, as mentioned in the function docstring here:
Returns ``None`` on subreddits that do not support the random feature. One
example, at the time of writing, is r/wallpapers.
But the reddit api seems to have changed and now praw will throw a prawcore.BadRequest instead.
Desired Result
Either restore previous functionality of the function returning None, or update the documentation to reflect the new behaviour.
Code to reproduce the bug
reddit=Reddit(**secret_credentials)
subreddit=reddit.subreddit('politecats')
random_post=subreddit.random() # throws a BadRequest
My code does not include sensitive credentials
Yes, I have removed sensitive credentials from my code.
Relevant Logs
Traceback (most recent call last):
File "C:\Users\Lev\.virtualenvs\Main_Website-TkBe3dLq\Lib\site-packages\flask\app.py", line 1498, in __call__
return self.wsgi_app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lev\.virtualenvs\Main_Website-TkBe3dLq\Lib\site-packages\flask\app.py", line 1476, in wsgi_app
response = self.handle_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lev\.virtualenvs\Main_Website-TkBe3dLq\Lib\site-packages\flask\app.py", line 1473, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lev\.virtualenvs\Main_Website-TkBe3dLq\Lib\site-packages\flask\app.py", line 882, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lev\.virtualenvs\Main_Website-TkBe3dLq\Lib\site-packages\flask\app.py", line 880, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lev\.virtualenvs\Main_Website-TkBe3dLq\Lib\site-packages\flask\app.py", line 865, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lev\Documents\Mine\Code\Websites\Flask\Main Website\site-docker\website\blueprints\random_reddit_images\views.py", line 19, in get_random_image
post = get_random_image_post(subreddit)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lev\Documents\Mine\Code\Websites\Flask\Main Website\site-docker\website\blueprints\random_reddit_images\views.py", line 25, in get_random_image_post
post = subreddit.random()
^^^^^^^^^^^^^^^^^^
File "C:\Users\Lev\.virtualenvs\Main_Website-TkBe3dLq\Lib\site-packages\praw\models\reddit\subreddit.py", line 3230, in random
self._reddit.get(url, params={"unique": self._reddit._next_unique})
File "C:\Users\Lev\.virtualenvs\Main_Website-TkBe3dLq\Lib\site-packages\praw\util\deprecate_args.py", line 46, in wrapped
return func(**dict(zip(_old_args, args)), **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lev\.virtualenvs\Main_Website-TkBe3dLq\Lib\site-packages\praw\reddit.py", line 731, in get
return self._objectify_request(method="GET", params=params, path=path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lev\.virtualenvs\Main_Website-TkBe3dLq\Lib\site-packages\praw\reddit.py", line 514, in _objectify_request
self.request(
File "C:\Users\Lev\.virtualenvs\Main_Website-TkBe3dLq\Lib\site-packages\praw\util\deprecate_args.py", line 46, in wrapped
return func(**dict(zip(_old_args, args)), **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lev\.virtualenvs\Main_Website-TkBe3dLq\Lib\site-packages\praw\reddit.py", line 963, in request
return self._core.request(
^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lev\.virtualenvs\Main_Website-TkBe3dLq\Lib\site-packages\prawcore\sessions.py", line 328, in request
return self._request_with_retries(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lev\.virtualenvs\Main_Website-TkBe3dLq\Lib\site-packages\prawcore\sessions.py", line 267, in _request_with_retries
raise self.STATUS_EXCEPTIONS[response.status_code](response)
prawcore.exceptions.BadRequest: received 400 HTTP response
This code has previously worked as intended
Yes
Operating System/Environment
Windows 10 and Linux raspberrypi 6.1.21
Python Version
3.12.4
PRAW Version
7.8.1
Links, references, and/or additional comments?
Subjectively, I also feel like subreddits that used to support .random() no longer do - it's possible that the reddit api has dropped the feature entirely (which would explain why the endpoint is now return a 400) but I have not checked this.
The text was updated successfully, but these errors were encountered:
Describe the Bug
Previously, if you called subreddit.random() on a subreddit which didn't support it, praw would simply return a None, as mentioned in the function docstring here:
praw/praw/models/reddit/subreddit.py
Lines 3214 to 3218 in 42f5236
But the reddit api seems to have changed and now praw will throw a prawcore.BadRequest instead.
Desired Result
Either restore previous functionality of the function returning None, or update the documentation to reflect the new behaviour.
Code to reproduce the bug
My code does not include sensitive credentials
Relevant Logs
This code has previously worked as intended
Yes
Operating System/Environment
Windows 10 and Linux raspberrypi 6.1.21
Python Version
3.12.4
PRAW Version
7.8.1
Links, references, and/or additional comments?
Subjectively, I also feel like subreddits that used to support .random() no longer do - it's possible that the reddit api has dropped the feature entirely (which would explain why the endpoint is now return a 400) but I have not checked this.
The text was updated successfully, but these errors were encountered: