python - 将 '' praw.Reddit'' 分配给变量时出现 KeyError

标签 python praw reddit

不久前我可以使用 oauth2 成功连接到 reddit 的服务器,但是当刚才运行我的脚本时,我收到一个 KeyError ,然后是一个 NoSectionError。下面的代码后面是异常,(代码已缩减至其要点)。

import praw


# Configuration
APP_UA = 'useragent'
...
...
...

r = praw.Reddit(APP_UA)

错误消息:

Traceback (most recent call last):
  File "D:\Directory\Python\lib\configparser.py", line 843, in items
    d.update(self._sections[section])
KeyError: 'useragent'

A NoSectionError occurred when handling the above exception.
"During handling of the above exception, another exception occurred:"

'Traceback (most recent call last):
  File "D:\Directory\Python\Projects\myprj for Reddit, globaloffensive\oddshotcrawler.py", line 19, in <module>
    r = praw.Reddit(APP_UA)
  File "D:\Directory\Python\lib\site-packages\praw\reddit.py", line 84, in __init__
    **config_settings)
  File "D:\Directory\Python\lib\site-packages\praw\config.py", line 47, in __init__
    raw = dict(Config.CONFIG.items(site_name), **settings)
  File "D:\Directory\Python\lib\configparser.py", line 846, in items
    raise NoSectionError(section)
configparser.NoSectionError: No section: 'useragent'
[Finished in 0.2s]

最佳答案

尝试给它一个 user_agent kwarg。

r = praw.Reddit(useragent=APP_UA)

关于python - 将 '' praw.Reddit'' 分配给变量时出现 KeyError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36361826/

相关文章:

python - 从 Windows 中的子进程检索标准输出

python - Shutil.rmtree(...) 在我的脚本中不起作用

python - 使用 pandas 根据行值将列转换为行

python - 使用 python PRAW 提取 reddit 评论并使用结果创建数据框

java - 从 reddit 下载图像时出现 java 错误

python - 条件 elif 语句未产生正确的结果

python - 使用 Praw 抓取 subreddit 帖子标题并将其用作文件名

python - 如何根据具体参数分配多个key :value dicts into an already established dictionary,

ios - 刷新 token 如何在 OAuth 流程中工作?

python - 未绑定(bind)的本地错误python