【问题标题】:Can't run simple python reddit program?无法运行简单的 python reddit 程序?
【发布时间】:2017-07-12 23:58:17
【问题描述】:

这里是python reddit 程序,代码100% 没问题。它来自一个教程网站。

#!/usr/bin/python
import praw

reddit = praw.Reddit('bot1')

subreddit = reddit.subreddit("learnpython")

for submission in subreddit.hot(limit=5):
print("Title: ", submission.title)
print("Text: ", submission.selftext)
print("Score: ", submission.score)
print("---------------------------------\n")

当我运行它时,我得到了这个错误。

Traceback (most recent call last):
File "Top3Links.py", line 4, in <module>
reddit = praw.Reddit('bot1')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-
packages/praw/reddit.py", line 105, in __init__
**config_settings)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-
packages/praw/config.py", line 64, in __init__
self.custom = dict(Config.CONFIG.items(site_name), **settings)
File 

“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ConfigParser.py”,第 347 行,在项目中 提高 NoSectionError(节) ConfigParser.NoSectionError:没有部分:'bot1' Eric-MacBook-Pro:PythonRedditBot Eric$

这可能与安装 python 3.5 有关,任何帮助都会很棒。

【问题讨论】:

  • 我可以肯定地说这个机器人需要python3,但你使用的是python2
  • 我怎样才能切换它..?
  • 您似乎忽略了设置 bot1 配置文件。
  • 它设置好了,几个月前我写了一个 python reddit 程序,但是我安装了新的 python,一切都搞砸了
  • 确保在 IDLE for python 3 中打开它,然后尝试运行代码。

标签: python reddit praw


【解决方案1】:

您似乎缺少此模块的配置文件。查看文档: https://praw.readthedocs.io/en/latest/getting_started/configuration/prawini.html

根据文档,您需要一个praw.ini 文件,其中包含如下部分:

[bot1]
client_id=Y4PJOclpDQy3xZ
client_secret=UkGLTe6oqsMk5nHCJTHLrwgvHpr
password=pni9ubeht4wd50gk
username=fakebot1

来源也可能提供信息:https://github.com/praw-dev/praw/blob/master/praw/reddit.py#L79

【讨论】:

  • 我去 reddit.py 文件并将代码粘贴到那个 github 上,它仍然给出同样的错误。
  • @ItachiSan 我刚刚编辑了我的帖子。我认为你需要一个 praw.ini 文件。
猜你喜欢
  • 1970-01-01
  • 2020-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-21
  • 2021-02-14
相关资源
最近更新 更多