ClientException: Invalid URL for Random Submission
See original GitHub issueIssue Description
For some subreddits an Invalid URL exception is thrown when I try to get a random submission.
Code:
import praw
from config.reddit import client
reddit = praw.Reddit(client_id = client['id'],
client_secret = client['secret'],
user_agent = client['agent'])
print(reddit.subreddit('pics').random()) # works
print(reddit.subreddit('wallpapers').random()) # does not work
Output:
7s53b4
Traceback (most recent call last):
File "./test.py", line 9, in <module>
print(reddit.subreddit('wallpapers').random()) # does not work
File "/usr/local/lib/python3.6/site-packages/praw/models/reddit/subreddit.py", line 339, in random
self._reddit.config.reddit_url, path))
File "/usr/local/lib/python3.6/site-packages/praw/models/reddit/submission.py", line 125, in __init__
self.id = self.id_from_url(url)
File "/usr/local/lib/python3.6/site-packages/praw/models/reddit/submission.py", line 41, in id_from_url
raise ClientException('Invalid URL: {}'.format(url))
praw.exceptions.ClientException: Invalid URL: https://www.reddit.com/r/wallpapers/
System Information
PRAW Version: 5.3.0 Python Version: 3.6.4 Operating System: Windows and Linux
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:8 (6 by maintainers)
Top Results From Across the Web
400 Bad Request Error: What It Is and How to Fix It
If the client is sending a request to an invalid URL — particularly one that is malformed via improper characters — this could...
Read more >Subreddit — PRAW 7.6.1 documentation - Read the Docs
Returns None on subreddits that do not support the random feature. One example, at the time of writing, is r/wallpapers. For example, to...
Read more >rtv/__init__.py at master · michael-lazar/rtv · GitHub
:param params: a dictionary containing the GET data to put in the url ... thing_ids or the URL is invalid. ... """Return a...
Read more >ECS TaskDefinition creation fails with error "Invalid ...
First of all I would recommend leaving the "hostPort" setting out. This allows ECS to choose a random host port dynamically, and then...
Read more >[Example code]-Random subreddit image to discord.py bot doesn't ...
Coding example for the question Random subreddit image to discord.py bot ... for x in memri_submissions if not x.stickied) await ctx.send(submission.url).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I appreciate the response! Thanks for looking into it.
Re-opening given the discussion that this might be intentional behavior on Reddit’s end.
It seems like this is the way to tell if a subreddit is excluded from /r/all. Even if there were such a setting, it’s not worth it to check since we get the feedback anyway. We could simply handle the ClientException for redirect inside
random
and raise a different exception in such cases. It would be good, however, to first get confirmation from Reddit that this is not actually a bug.