You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PRAW登录Reddit遇USER_REQUIRED错误,求解决方法

修复PRAW提交内容时的USER_REQUIRED登录错误

你的代码里存在一个拼写错误:初始化praw.Reddit对象时,参数名写成了pasword,正确拼写应为password。这个错误导致PRAW无法正确读取用户密码,进而触发登录失败的异常。

修正后的代码

import json
import praw

subr = 'test'
credentials = 'client_secrets.json'

with open(credentials) as f:
    creds = json.load(f)

# 修正password的拼写错误
reddit = praw.Reddit(client_id=creds['client_id'],
                     client_secret=creds['client_secret'],
                     user_agent=creds['user_agent'],
                     redirect_uri=creds['redirect_uri'],
                     password=creds['password'],
                     username=creds['username'])

title = "PRAW documentation"
url = "https://praw.readthedocs.io"
reddit.subreddit("test").submit(title, url=url)

额外检查项

  • 确认client_secrets.json里的password键名和代码中引用的一致,无拼写错误
  • 确保你的Reddit应用类型为脚本应用(script),仅脚本应用支持直接通过用户名密码登录
  • 检查redirect_uri是否与Reddit应用设置中填写的内容一致(脚本应用通常填写http://localhost:8080即可)

内容的提问来源于stack exchange,提问作者MasterMind

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 03:25:33