如何解决Python praw错误:AttributeError:'module'对象没有属性'对象'

时间:2016-12-29 17:37:25

标签: python reddit praw

这是代码 - 我尝试谷歌但没有找到解决方案:(

array (size=5)
  ':UID' => string '66' (length=2)
  ':ORDER_BY' => string 'id' (length=2)
  ':ORDER_TYPE' => string 'asc' (length=3)
  ':START' => string '0' (length=1)
  ':DATA_LENGTH' => string '25' (length=2)

1 个答案:

答案 0 :(得分:2)

没有praw.objects子模块。你想要的是praw.models,你应该可能在顶部显式导入。以下可能适合您。干杯!

import praw
import praw.models
import sys
AUTOREPLY_MSG = """\                                                                                          
Hey there, I'm on a vacation for x days.                                                                      

I won't check this account till then. Happy Holidays! """                                                     


def main():                                                                                                   
    r = praw.Reddit('bot1', user_agent='bot1 user agent')                                                     

    for msg in r.inbox.unread(mark_read=True):                                                                
        if isinstance(msg, praw.models.Message):                                                             
            msg.reply(AUTOREPLY_MSG)                                                                          
            msg.mark_as_read()                                                                                
            print(msg, file=sys.stderr)                                                                       


if __name__ == '__main__':                                                                                    
    main()