M. Kleiven M. Kleiven - 26 days ago 10
Python Question

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

I started programming a reddit script a few weeks ago, the project was postponed. Although incomplete, I could successfully connect to reddit's servers with oauth2, but when running the script just now, I get a

KeyError
followed by a
NoSectionError
. Code is below followed by exceptions, (The code has been reduced to its essentials).

import praw


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

r = praw.Reddit(APP_UA)


Error message:

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\Oddshotcrawler 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]

Answer

Try giving it a user_agent kwarg.

r = praw.Reddit(useragent=APP_UA)