使用PRAW有很多错误

2024-03-29 14:21:16 发布

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

我运行代码,它会给我一堆错误,比如“无效的授权错误处理请求”。在我的实际代码中,我的id和密码设置正确。我做错什么了?你知道吗

import random
import praw

jokes = open('jokelist.txt').read().splitlines()
joke = ''

#Sets up base of bot
reddit = praw.Reddit(client_id='',
                             client_secret = '',
                             username = 'JokeMeBot',
                             password = '',
                             user_agent = 'JokeMeBot by /u/Tawkins')


#sets the subreddit
subreddit = reddit.subreddit('dadjokes')

#how to call the bot
keyword = '!JokeMe'
#Checks if the keyword is in the subreddit
for comment in subreddit.stream.comments():
    if keyword in comment.body:
#sets to a random joke and posts
        joke = random.choice(jokes)
        comment.reply(joke)
        print('posted')
    else:
        print("oops")

Tags: the代码inimportclientidbotcomment
1条回答
网友
1楼 · 发布于 2024-03-29 14:21:16

从praw文件:

https://praw.readthedocs.io/en/latest/getting_started/authentication.html#script-application

Note

If the following exception is raised, double check your credentials, and ensure that that the username and password you are using are for the same user with which the application is associated:

OAuthException: invalid_grant error processing request

所以我会仔细检查你的证件,看看能不能解决这个问题。 请记住,用户名是您的reddit帐户名,而不是bot的名称。你知道吗

相关问题 更多 >