Skip to content

Fix API endpoint for hide#2099

Open
volker-fr wants to merge 3 commits intopraw-dev:mainfrom
volker-fr:main
Open

Fix API endpoint for hide#2099
volker-fr wants to merge 3 commits intopraw-dev:mainfrom
volker-fr:main

Conversation

@volker-fr
Copy link
Copy Markdown

Fixes # (provide issue number if applicable)
404 NotFound error on api/hide endpoint

Feature Summary and Justification

The hide API endpoint seemed to have changed the last 24h. The result is that praw is failing on hiding posts.

What is not fully clear to me are all the other endpoints. They all end in /. At the same time, the API documentation doesn't document any of those with a trailing slash.

It might be beneficial to remove that in other API calls in the future. For my used scripts, the current by praw utilized API endpoints work fine. At the same time there are other API endpoints in praw/endpoints.py without a trailing slash.

References

#!/usr/bin/env python3
"""
Demonstrates the PRAW hide() bug:
- submission.hide() returns 404 (uses /api/hide/ with trailing slash)
- reddit.post("api/hide") succeeds (no trailing slash)
"""

import os
import praw
from prawcore.exceptions import NotFound

reddit = praw.Reddit(
    client_id=os.environ["REDDIT_APP_ID"],
    client_secret=os.environ["REDDIT_APP_SECRET"],
    user_agent="PRAW hide bug demo",
    username=os.environ["REDDIT_USER"],
    password=os.environ["REDDIT_PASSWORD"],
)

# Get a test submission
sub = next(reddit.subreddit("AskReddit").new(limit=1))
print(f"Submission: {sub.fullname}")
print(f"Title: {sub.title[:50]}...")

# Method 1: Raw API call (works)
print("\n1. Raw API call (reddit.post):")
try:
    reddit.post("api/hide", data={"id": sub.fullname})
    print("   ✓ SUCCESS")
    reddit.post("api/unhide", data={"id": sub.fullname})
except Exception as e:
    print(f"   ✗ FAILED: {e}")

# Method 2: PRAW's hide() (broken - uses /api/hide/)
print("\n2. PRAW submission.hide():")
try:
    sub.hide()
    print("   ✓ SUCCESS")
    sub.unhide()
except NotFound:
    print("   ✗ FAILED: 404 NotFound")
    print("   (PRAW uses 'api/hide/' with trailing slash - Reddit now 404s this)")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant