PRAW 错误更新到新的 Python 发行版



所以我正在尝试创建一个机器人,使用来自u/GoldenSights的一些代码将帖子从sub(r/pics(交叉到(r/polpics(。 我升级到一个新的python发行版,我遇到了很多错误,我什至不知道从哪里开始。 这是代码(格式关闭,错误行粗体(:

Traceback (most recent call last):
  File "C:UserstonycAppDataLocalProgramsPythonPython36-32Libsite-
packagesprawsubdump.py", line 84, in <module>
    r = praw.Reddit(USERAGENT)
  File "C:UserstonycAppDataLocalProgramsPythonPython36-32libsite-
packagesprawreddit.py", line 150, in __init__
    raise ClientException(required_message.format(attribute))
praw.exceptions.ClientException: Required configuration setting 'client_id' 
missing.
This setting can be provided in a praw.ini file, as a keyword argument to the `Reddit` class constructor, or as an environment variable.

这似乎与用户代理设置有关。 我认为我没有正确配置。

USERAGENT = ""
# This is a short description of what the bot does. For example 
"/u/GoldenSights' Newsletter bot"
SUBREDDIT = "pics"
# This is the sub or list of subs to scan for new posts.
# For a single sub, use "sub1".
# For multiple subs, use "sub1+sub2+sub3+...".
# For all use "all"
KEYWORDS = ["It looks like this post is about US Politics."]
# Any comment containing these words will be saved.
KEYDOMAINS = []
# If non-empty, linkposts must have these strings in their URL

这是错误行:

print('Logging in')
r = praw.Reddit(USERAGENT) <--here, this is error line 84
r.set_oauth_app_info(APP_ID, APP_SECRET, APP_URI)
r.refresh_access_information(APP_REFRESH)

同样在 Reddit.py:

raise ClientException(required_message.format(attribute)) <--- error
praw.exceptions.ClientException: Required configuration setting 'client_id' 
missing.
This setting can be provided in a praw.ini file, as a keyword argument to 
the `Reddit` class constructor, or as an environment variable.

首先,您需要将 API 凭据存储在 praw.ini 文件中。这使事情变得更加安全,并且看起来它可能会以某种方式解决您的问题。这是完整的 praw.ini 文件的样子,包括用户代理,因此请尝试复制它。

[DEFAULT]
# A boolean to indicate whether or not to check for package updates.
check_for_updates=True
# Object to kind mappings
comment_kind=t1
message_kind=t4
redditor_kind=t2
submission_kind=t3
subreddit_kind=t5
# The URL prefix for OAuth-related requests.
oauth_url=https://oauth.reddit.com
# The URL prefix for regular requests.
reddit_url=https://www.reddit.com
# The URL prefix for short URLs.
short_url=https://redd.it
[appname]
 client_id=IE*******T14_w
client_secret=SW***********************CLY
password=******************
username=appname
user_agent=web:appname:1.0.0 (by /u/username)

在你解决这个问题后,让我知道事情进展如何。

最新更新