[英]Flasgger AttributeError: 'NoneType' object has no attribute 'get'?
[英]Praw AttributeError: 'NoneType' object has no attribute 'get_comments'
我編寫了一個簡單的腳本,用於識別對某些子Reddit做出貢獻的用戶。 作為免責聲明,如果您打算使用此代碼,則應確保對數據進行匿名處理(正如我所希望的那樣,通過匯總數據並刪除所有用戶名)。 它可以與某些subreddit一起使用,但似乎並不十分健壯,如使用/ r / nba運行該錯誤時所看到的以下錯誤所示:
AttributeError:“ NoneType”對象沒有屬性“ get_comments”
下面是我的代碼:
import praw
import pprint
users = [] #[username, flair, comments]
r=praw.Reddit(user_agent="user_agent")
r.login("username", "password")
submissions = r.get_subreddit('nba').get_top(limit=1) #won't work with higher limit?
for submission in submissions:
submission.replace_more_comments(limit=3, threshold=5)
flat_comments = praw.helpers.flatten_tree(submission.comments)
for comment in flat_comments:
user_comments = []
for i in comment.author.get_comments(limit=2):
user_comments.append(i.body)
#user_comments.append(str(i.body)) #sometimes causes an error as well
users.append([str(comment.author), comment.author_flair_text, user_comments])
pprint.pprint(users)
當我將subreddit更改為“ python”時,似乎遇到的問題較少,因此希望有人可以指出我所缺少的內容。 提前致謝!
好了,你看到了
for i in comment.author.get_comments(limit=2):
我認為您的代碼失敗,因為
comment.author is None
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.