无法使用PRAW API提交帖子

时间:2019-03-25 23:56:24

标签: python-3.x reddit praw

我有此代码:

$('.button1').one('click', function(){

  $('.output0').delay(10000).fadeOut(500);
  $('.output1').delay(10500).show(0);

  jQuery(function($) {
        $('.timer').countTo({
            from: 10,
            to: 0,
            speed: 10000,
            refreshInterval: 50,
            onComplete: function(value) {
                console.debug(this);
            }
        });
    });
});

但是它返回错误:

import praw

print('starting')
reddit = praw.Reddit(client_id='****',
                     client_secret='********',
                     user_agent='****',
                     username = '****',
                     password = '****')

r = reddit.post("/api/submit",data={'title':'my firts title','text':'the text of my post','sr':'r/test'})

print("finishing")

,并且在某些情况下,相同的代码返回:

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-19-7e66ffa81635> in <module>
      9                      password = '*****')
     10 
---> 11 r = reddit.post("/api/submit",data={'title':'my firts title','text':'the text of my post','sr':'r/test'})
     12 
     13 print("finishing")

~\AppData\Local\Continuum\anaconda3\lib\site-packages\praw\reddit.py in post(self, path, data, files, params)
    481         data = self.request('POST', path, data=data or {}, files=files,
    482                             params=params)
--> 483         return self._objector.objectify(data)
    484 
    485     def put(self, path, data=None):

~\AppData\Local\Continuum\anaconda3\lib\site-packages\praw\objector.py in objectify(self, data)
    148             if len(errors) == 1:
    149                 raise APIException(*errors[0])
--> 150             assert not errors
    151 
    152         elif isinstance(data, dict):

AssertionError: 

说实话,我不知道我在做什么错。我想有一种更好的方法来简单地在reddit中提交帖子,但是文档不是那么有用

1 个答案:

答案 0 :(得分:2)

您应该这样做:

my_post = reddit.subreddit('subreddit').submit('My Title', selftext='Stuff you want to put in the textbox')

请注意,subreddit不应包含r/。

按: https://praw.readthedocs.io/en/latest/code_overview/models/subreddit.html#praw.models.Subreddit.submit