2016-12-06 29 views
3

我試圖從用戶檢索最後1000條評論,因爲1000是Reddit限制。使用PRAW獲取Reddit用戶註釋導致TypeError:'SubListing'對象不可調用錯誤

我跟着代碼示例here,並修改了更新API的一些調用。比如user.get_comments現在好像只是user.comments。

這是我運行的代碼。

import praw 

my_user_agent = 'USERAGENT' 
my_client_id = 'CLIENTID' 
my_client_secret = 'SECRET' 

r = praw.Reddit(user_agent=my_user_agent, 
        client_id=my_client_id, 
        client_secret=my_client_secret) 

user = r.redditor('REDDITUSERNAME') 

for comment in user.comments(limit=None): 
    print comment.body 

雖然我每次都會在最後一行發生錯誤。

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
TypeError: 'SubListing' object is not callable 

我已經連接到所述API和具有如我可以做打印(user.comment_karma)的有源連接,並將其正確顯示。

任何想法我做錯了什麼?

+0

你不應該使用代碼格式的錯誤日誌,[元問題](http://meta.stackoverflow.com/questions/276966/quote-formatting-messing-up-how-to-handle-format -of-錯誤日誌)。 – Stargateur

+0

@Stargateur感謝您的收穫。根據meta post編輯問題。 – TheBeginningEnd

+0

你在使用PRAW 3還是4?自從這個例子以來,我相信這個API可能會發生一些變化。 – Aurora0001

回答

4

根據文檔,commentsRedditor模型在PRAW 4中的屬性,而不是函數。因此,調用.comments(limit=None)是無效的語法,因爲.comments不是函數。相反,你必須指定一個列表排序順序,像這樣,因爲SubListing對象(什麼user.comments是)從BaseListingMixin繼承:

for comment in user.comments.new(): 
    print(comment.body) 

無可否認,對於PRAW 4文檔是很清楚的,你可能會通過直接搜索代碼找到最好的文檔。

+0

這會導致相同的錯誤。 – TheBeginningEnd

+0

這很奇怪,屬性[絕對存在](https://github.com/praw-dev/praw/blob/praw4/praw/models/listing/mixins/redditor.py#L13)。 'user = r.redditor('REDDITUSERNAME')'有什麼幫助嗎? (而不是'get_redditor') – Aurora0001

+1

很抱歉忘記在代碼中改變它。它現在只是r.redditor而不是r.get_redditor,這就是我正在使用的,我只是在修復錯誤之前複製並粘貼代碼塊。我現在編輯了問題中的代碼。 – TheBeginningEnd

相關問題