Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8628689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:36:38+00:00 2026-06-12T08:36:38+00:00

I am using PRAW for Reddit API in a Python/GTK application. I have been

  • 0

I am using PRAW for Reddit API in a Python/GTK application. I have been successful in using the API, but I can’t seem to be able to decode the JSON for use. It should be known that I am a beginner in Python and GTK applications.

# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
### BEGIN LICENSE
# This file is in the public domain
### END LICENSE

import gettext
from gettext import gettext as _
gettext.textdomain('redditreader')

from gi.repository import Gtk # pylint: disable=E0611
import logging
logger = logging.getLogger('redditreader')

from redditreader_lib import Window
from redditreader.AboutRedditreaderDialog import AboutRedditreaderDialog
from redditreader.PreferencesRedditreaderDialog import PreferencesRedditreaderDialog

import praw

import json
import simplejson
from pprint import pprint

# See redditreader_lib.Window.py for more details about how this class works
class RedditreaderWindow(Window):
    __gtype_name__ = "RedditreaderWindow"

    def finish_initializing(self, builder): # pylint: disable=E1002
        """Set up the main window"""
        super(RedditreaderWindow, self).finish_initializing(builder)

        self.AboutDialog = AboutRedditreaderDialog
        self.PreferencesDialog = PreferencesRedditreaderDialog

        # Code for other initialization actions should be added here.
r = praw.Reddit(user_agent='example')
try:
    submissions = r.get_front_page(limit=5)
    [str(x) for x in submissions]
    jsondatafirst = simplejson.loads(str(submissions))
    jsondata = unicode(jsondatafirst, 'utf-8')
    print(jsondata)
except (simplejson.decoder.JSONDecodeError, ValueError):
    print 'Decoding JSON has failed'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:36:39+00:00Added an answer on June 12, 2026 at 8:36 am

    With PRAW you do not need to do any json decoding as PRAW handles all of that for you.

    Say for example for each submission you want to print out the number of upvotes, the number of downvotes, and the submission title. You could do:

    for submission in r.get_front_page(limit=5):
        print submission.ups, submission.downs, submission.title
    

    If you want to see all the attributes available to use on a submission object you can run:

    import pprint
    for submission in r.get_front_page(limit=5):
        pprint.pprint(vars(submission))
    

    Additionally if you want to get the comments from a submission then you can use the submission.comments property. You can also manually look at the json response for a request to see what attributes should be available through PRAW (example).

    The attributes are not explicitly listed anywhere for the objects because the attributes are created directly from whatever the key name is in the associated json response for the request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the HTML5 File API I can get the Binary String representation of a
Using Android TelephonyManager an application can obtain the state of data activity over the
Using PyGtk's IconView, I can set the icons to be reorderable by calling gtk.IconView.set_reorderable(True)
Using Python, I'm trying to connect to my AppEngine app's remote_api handler, but I
Using PyObjC , you can use Python to write Cocoa applications for OS X.
I'm using the praw reddit library to pull data from reddit and I ran
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
Using android 2.3.3, I have a background Service which has a socket connection. There's
Using jQuery, one can easily find out whether a particular element is visible using
Using NSDateComponents I know how to get the day component, but this gives me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.