Search code examples
pythonredditpraw

How to solve Python praw error : AttributeError: 'module' object has no attribute 'objects'


Here is code - I try google but did not find solution :(

#!/usr/bin/env python3                                                                                        
import praw                                                                                                   
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.objects.Message):                                                             
            msg.reply(AUTOREPLY_MSG)                                                                          
            msg.mark_as_read()                                                                                
            print(msg, file=sys.stderr)                                                                       


if __name__ == '__main__':                                                                                    
    main()                                                                                                    
~              

Solution

  • There is no praw.objects submodule. What you want is praw.models and you should probably import that explicitly at the top. The following might work for you. Cheers!

    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()