question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ClientException: Invalid URL for Random Submission

See original GitHub issue

Issue 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
jarhill0commented, Jan 24, 2018

I appreciate the response! Thanks for looking into it.

1reaction
bboecommented, Jan 23, 2018

Re-opening given the discussion that this might be intentional behavior on Reddit’s end.

As far as I can tell, there is no way to tell whether a subreddit is excluded from /r/all.

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found