将“'praw.Reddit'”分配给变量时出现 KeyError

KeyError when assigning ''praw.Reddit'' to variable

前段时间我可以使用 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)