PRAW错误更新到新的Python Dis

2024-04-26 15:10:33 发布

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

因此,我尝试创建一个bot,它使用u/GoldenSights中的一段代码,将sub(r/pics)和(r/polpics)的文章交叉。我升级到了一个新的python发行版,出现了很多错误,我甚至不知道从哪里开始。以下是代码(格式为关闭,错误行为粗体):

Traceback (most recent call last):
  File "C:\Users\tonyc\AppData\Local\Programs\Python\Python36-32\Lib\site-
packages\praw\subdump.py", line 84, in <module>
    r = praw.Reddit(USERAGENT)
  File "C:\Users\tonyc\AppData\Local\Programs\Python\Python36-32\lib\site-
packages\praw\reddit.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设置有关。我想我没有正确的配置。你知道吗

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.

Tags: theinpyappforisasbot
1条回答
网友
1楼 · 发布于 2024-04-26 15:10:33

首先,您需要将API凭证存储在praw.ini file中。这会让事情变得更加安全,看起来可能会在某种程度上解决你的问题。以下是一个完整的普拉维尼文件看起来像,包括useragent,所以尝试复制这个。你知道吗

[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)

等你把事情解决了再告诉我。你知道吗

相关问题 更多 >