2016-04-01 27 views
2

değişkenine atama yaparken, bir süre önce reddit'in sunucularına oauth2 ile başarılı bir şekilde bağlanabildiğim, ancak şimdi betiğimi çalıştırırken, KeyError ve ardından NoSectionError aldım. Kod aşağıda istisnalar vardır, (Kod, esaslarına indirgenmiştir).KeyError '' praw.Reddit '' öğesini

import praw 


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

r = praw.Reddit(APP_UA) 

Hata mesajı:

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] 

cevap

3

it a user_agent kwarg vererek deneyin.

r = praw.Reddit(useragent=APP_UA) 
+0

çalıştı, ama yeni bir traceback hata verdi: 'traceback (son En son çağrı): Dosya "D: Reddit için \ Dizin \ Python \ Projects \ Oddshotcrawler, globaloffensive \ oddshotcrawler.py", satır 19, r = praw.Reddit (useragent = APP_UA) Dosya "D: \ Directory \ Python \ lib \ site-paketleri \ praw \ reddit.py", satır 92, in __init__ yükseltmek ClientException (message.format (öznitelik))) praw.exceptions.ClientException: Gerekli yapılandırma ayarı 'client_id' eksik. Bu ayar praw.ini dosyasında, 'Reddit' sınıf yapıcısına bir anahtar kelime bağımsız değişkeni olarak veya bir ortam değişkeni olarak sağlanabilir. ' –

+0

botunuzun yetkilendirilmesi gerekiyor gibi görünüyor, burada okuyabilirsiniz http: //praw.readthedocs.org/tr/stable/pages/oauth.html – John

+0

APP_UA nedir? Tam bir çalışma örneği bulmaya çalışıyorum ama yapamadım. Praw.Reddit –

İlgili konular