Praw AttributeError:无法设置attribu

2024-06-09 21:26:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我编写了一个reddit机器人,它将搜索subreddit的评论,如果有评论说感觉它会回复它。然后,它将注释id写入一个文本文件,这样它就不会对同一个注释进行两次注释。在

代码如下:

import praw
import time
import sys
import random

r = praw.Reddit('Posts Feels gif in response to someone saying feels'
                'by: Mjone77')
r.login('Feels_Bot', 'nottherealpassword')
file = open('Commentids.txt', 'r')
already_done = file.read()
file.close()
times = 0
feels = 0


while True:
   # try: 
        subreddit = r.get_subreddit('frozen')
        subreddit_comments = subreddit.get_comments()
        times+=1
        for comment in subreddit_comments:
            commentSays = comment.body
            commentSays = commentSays.lower()
            #print(commentSays)
            #print('\n')
            #if 'stop feels_bot' in commentSays:
                #sys.exit("Commanded to stop.")
            if comment.id not in already_done and 'feels' in commentSays:
                gif = random.randrange(0,3)
                if gif == 0:
                    comment.reply('[Relevant](http://i.imgur.com/pXBrf.gif)\n\n___\n\n^I ^am ^a ^bot ^not ^a ^real ^redditor \n\n ^Please ^contact ^/u/Mjone77 ^with ^any ^problems')
                if gif == 1:
                    comment.reply('[Relevant](http://gfycat.com/BraveSerpentineAzurevase)\n\n___\n\n^I ^am ^a ^bot ^not ^a ^real ^redditor \n\n ^Please ^contact ^/u/Mjone77 ^with ^any ^problems')
                if gif == 2:
                    comment.reply('[Relevant](http://www.gfycat.com/PlushMeanCowrie)\n\n___\n\n^I ^am ^a ^bot ^not ^a ^real ^redditor \n\n ^Please ^contact ^/u/Mjone77 ^with ^any ^problems')
                already_done = already_done+' '+comment.id
                file = open('Commentids.txt', 'w')
                file.write(already_done)
                file.close()
                #print('Commented~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
                time.sleep(5)
                feels+=1
        print('\n\n\n\n\n\n\n')        
        print('Feels:')
        print(feels)
        print('Times Ran:')
        print(times)
        time.sleep(60)
    #except AttriuteError:
        #pass

我运行它,让它继续运行,然后返回到一个HTTP错误504:Gateway超时。有没有人知道如何防止这种情况发生,或者让它等60秒后再试一次?在

另外,当我再次运行它时,没有更改工作程序中的任何代码,它决定给我这个:

^{pr2}$

它不再运行了,有人知道如何修复这个错误吗?在


Tags: inimportifbotcommentnotgiffile
1条回答
网友
1楼 · 发布于 2024-06-09 21:26:26

我相信这个错误是这个recent reddit update造成的。在

从上面的链接:

This change may also have some unexpected side-effects on third-party extensions/apps/etc. that display or otherwise use the specific up/down numbers. We've tried to take various precautions to make the transition smoother, but please let us know if you notice anything going horribly wrong due to it.

我今天开始用我自己的机器人来体验它,而且代码没有改变。在

I posted an issue on the PRAW Github repo here.

编辑:AttributeError已修复。请确保您将PRAW更新到最新版本,它应该可以再次工作。在

相关问题 更多 >