Python 3.x 无法使用PRAW API提交帖子

Python 3.x 无法使用PRAW API提交帖子,python-3.x,reddit,praw,Python 3.x,Reddit,Praw,我有以下代码: import praw print('starting') reddit = praw.Reddit(client_id='****', client_secret='********', user_agent='****', username = '****', password = '****') r =

我有以下代码:

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: 
---------------------------------------------------------------------------
AssertionError回溯(上次最近的调用)
在里面
9密码=“****”)
10
--->11 r=reddit.post(“/api/submit”,data={'title':'my firts title','text':'the text of my post','sr':'r/test'})
12
13打印(“整理”)
post中的~\AppData\Local\Continuum\anaconda3\lib\site packages\praw\reddit.py(self、path、data、files、params)
481 data=self.request('POST',path,data=data或{},files=files,
482参数=参数)
-->483返回self.\u objector.objectify(数据)
484
485 def put(自身、路径、数据=无):
objectify中的~\AppData\Local\Continuum\anaconda3\lib\site packages\praw\objector.py(self,data)
148如果len(误差)=1:
149引发异常(*错误[0])
-->150断言不是错误
151
152 elif isinstance(数据、指令):
断言者错误:
在某些情况下,相同的代码返回:

---------------------------------------------------------------------------
APIException                              Traceback (most recent call last)
<ipython-input-27-b62f9f5f585d> 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)
    147             errors = data['json']['errors']
    148             if len(errors) == 1:
--> 149                 raise APIException(*errors[0])
    150             assert not errors
    151 

APIException: INVALID_OPTION: 'opci\xf3n inv\xe1lida' on field 'sr'
---------------------------------------------------------------------------
APIException回溯(最近一次调用上次)
在里面
9密码=“****”)
10
--->11 r=reddit.post(“/api/submit”,data={'title':'my firts title','text':'the text of my post','sr':'r/test'})
12
13打印(“整理”)
post中的~\AppData\Local\Continuum\anaconda3\lib\site packages\praw\reddit.py(self、path、data、files、params)
481 data=self.request('POST',path,data=data或{},files=files,
482参数=参数)
-->483返回self.\u objector.objectify(数据)
484
485 def put(自身、路径、数据=无):
objectify中的~\AppData\Local\Continuum\anaconda3\lib\site packages\praw\objector.py(self,data)
147错误=数据['json']['errors']
148如果len(误差)=1:
-->149引发异常(*错误[0])
150断言不是错误
151
APIException:无效的_选项:“opci\xf3n inv\xe1lida”位于字段“sr”
老实说,我不知道我做错了什么。我认为有一种更好的方法可以用reddit简单地提交帖子,但文档并没有那么大帮助

您应该:

my_post = reddit.subreddit('subreddit').submit('My Title', selftext='Stuff you want to put in the textbox')
请注意,
subreddit
不应包括r/

根据: 你应该做:

my_post = reddit.subreddit('subreddit').submit('My Title', selftext='Stuff you want to put in the textbox')
请注意,
subreddit
不应包括r/

根据:

没问题。praw文档中有很多好东西。在/r/redditdev上搜索内容也是值得的,因为有更多的人在那里签入,可以回答更具体的内容。没问题。praw文档中有很多好东西。在/r/redditdev上搜索内容也是值得的,因为有更多的人在那里签入,可以回答更具体的内容。