How to solve Python praw error : AttributeError: 'module' object has no attribute 'objects'
How to solve Python praw error : AttributeError: 'module' object has no attribute 'objects'
这是代码 - 我尝试 google 但没有找到解决方案:(
#!/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()
~
没有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()
这是代码 - 我尝试 google 但没有找到解决方案:(
#!/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()
~
没有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()