python - 错误: PYTHON DJANGO PRAW REDDIT-API

标签 python django reddit praw

使用 Praw 4.4.0 在 Python 2.7 虚拟环境中本地构建 Django 1.8 Web 应用程序。

该项目名为demonstration,并有一个名为app的应用

enter image description here

自动取款机,

enter image description here

这是访问以下结果的一部分:http://127.0.0.1:8000/app/profile/

app/views.py 具有以下配置文件代码:

# 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 ...

正如您在第二张图片中看到的,Reddit 子版 block 的名称被打印出来。 太棒了

嗯,不太好。这是在代码中编写的,所以它不是从 Reddit 获取的,请参阅:

subreddit = reddit.subreddit('redditdev')

print(subreddit.display_name)  # Output: redditdev

一旦它真正尝试访问 Reddit 并吸收数据,结果就是:

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

使用Debug mode = True,可以在页面中看到以下内容:

enter image description here

问题:不知何故,Reddit 不喜欢我的登录。

他们怎么会开始喜欢我并允许我打印数据?

我可以在哪些方面做得更好?

感谢您的支持

\\\\一些有用的链接////////

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

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

最佳答案

已修复。 问题是:

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

删除它然后开始工作。

enter image description here

关于python - 错误: PYTHON DJANGO PRAW REDDIT-API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42535140/

相关文章:

python - 检查 django 形式中的值是否相同

python - Django 或 mod_wsgi 在运行时会修改 sys.path 吗?

python - 使用 PRAW 提交帖子

javascript - 点击发送数据

java - 尝试使用 Java 向 Reddit 发表评论

Python FeedParser 很好地格式化 Reddit

python - 当数据流入 python 时,将数据输出到文本文件中

python - 初始化一个字典,其中每个项目都是空的唯一列表的列表

python - 如何检查时间戳和日期,然后删除不匹配

python - 使用 PIL 绘制图像的更快方法?