Search code examples
pythondjangoredditpraw

Error: PYTHON DJANGO PRAW REDDIT-API


building locally a Django 1.8 web app in a Python 2.7 virtual env using Praw 4.4.0.

The project is called demonstration and has an app called app

enter image description here

Atm,

enter image description here

This is part of the result when going to: http://127.0.0.1:8000/app/profile/

app/views.py has the following code for profile:

# views.py

from django.shortcuts import render, HttpResponse
import requests
import praw


# Create your views here.
    def profile(request):
        reddit = praw.Reddit(client_id='client_id',
                      client_secret='client_secret',
                      username='username',
                      password='password',
                      user_agent='user_agent')
        # assume you have a Reddit instance bound to variable `reddit`
        subreddit = reddit.subreddit('redditdev')

        print(subreddit.display_name)  # Output: redditdev
        print(subreddit.title)  # Output: reddit Development
        print(subreddit.description)  # Output: A subreddit for discussion of ...

As you can see in the second image, the name of the subreddit gets printed. Great.

Well, not so great. That was written in the code, so it's not picking up from Reddit, see:

subreddit = reddit.subreddit('redditdev')

print(subreddit.display_name)  # Output: redditdev

Once it actually tries to go to Reddit and suck up the data, this is the result:

print(subreddit.title)  # Output: reddit Development
print(subreddit.description)  # Output: A subreddit for discussion of ...

[01/Mar/2017 14:50:02]"GET /app/profile/ HTTP/1.1" 500 93288

Using Debug mode = True, one can see the following in the page:

enter image description here

Problem: somehow, Reddit is not liking my login.

How can they start to like me and allow me to print the data?

What can I do better?

Thank you for your support

\\\\\Some helpful links////////

http://praw.readthedocs.io/en/latest/getting_started/quick_start.html

https://pypi.python.org/pypi/praw


Solution

  • Fixed. The problem was:

    username='username',
    password='password',
    

    Removed it and then started to work.

    enter image description here