M. Kleiven M. Kleiven - 1 year ago 159
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

followed by a
. 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
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__
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 Source

Try giving it a user_agent kwarg.

r = praw.Reddit(useragent=APP_UA)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download