这是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
&#34; /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ConfigParser.py" ;,第347行,项目 提出NoSectionError(部分) ConfigParser.NoSectionError:没有部分:&#39; bot1&#39; Eric-MacBook-Pro:PythonRedditBot Eric $
它可能与安装python 3.5有关,任何帮助都会很棒。
答案 0 :(得分:0)
您似乎缺少此模块的配置文件。查看文档: 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