PRAW在检索注释和线程时获得400 HTTP响应

时间:2018-12-14 09:55:35

标签: python praw

我正在执行以下操作来检索用户评论:

reddit_user = praw.Reddit(client_id=settings.CLIENT_ID,
             client_secret=CLIENT_SECRET,
             refresh_token= token,
             user_agent=USER_AGENT)

user = reddit_user.redditor(reddit_username)
for comment in user.comments.new(limit=15):
        thread_comments.append(comment)

上面的代码有时会起作用,但其他时候会引发以下异常:

Traceback (most recent call last):
  File "/home/admin/project/env/lib/python3.5/site-packages/celery/app/trace.py", line 382, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/home/admin/project/env/lib/python3.5/site-packages/celery/app/trace.py", line 641, in __protected_call__
    return self.run(*args, **kwargs)
  File "/home/admin/project/main/tasks.py", line 171, in check_user_reddit_threads
    submissions = reddit.reddit_user_threads(usr.reddit_username, 15)
  File "/home/admin/project/scripts/reddit.py", line 57, in reddit_user_threads
    for submission in user.submissions.new(limit=results_limit):
  File "/home/admin/project/env/lib/python3.5/site-packages/praw/models/listing/generator.py", line 52, in __next__
    self._next_batch()
  File "/home/admin/project/env/lib/python3.5/site-packages/praw/models/listing/generator.py", line 62, in _next_batch
    self._listing = self._reddit.get(self.url, params=self.params)
  File "/home/admin/project/env/lib/python3.5/site-packages/praw/reddit.py", line 391, in get
    data = self.request('GET', path, params=params)
  File "/home/admin/project/env/lib/python3.5/site-packages/praw/reddit.py", line 506, in request
    params=params)
  File "/home/admin/project/env/lib/python3.5/site-packages/prawcore/sessions.py", line 185, in request
    params=params, url=url)
  File "/home/admin/project/env/lib/python3.5/site-packages/prawcore/sessions.py", line 116, in _request_with_retries
    data, files, json, method, params, retries, url)
  File "/home/admin/project/env/lib/python3.5/site-packages/prawcore/sessions.py", line 101, in _make_request
    params=params)
  File "/home/admin/project/env/lib/python3.5/site-packages/prawcore/rate_limit.py", line 35, in call
    kwargs['headers'] = set_header_callback()
  File "/home/admin/project/env/lib/python3.5/site-packages/prawcore/sessions.py", line 145, in _set_header_callback
    self._authorizer.refresh()
  File "/home/admin/project/env/lib/python3.5/site-packages/prawcore/auth.py", line 209, in refresh
    refresh_token=self.refresh_token)
  File "/home/admin/project/env/lib/python3.5/site-packages/prawcore/auth.py", line 138, in _request_token
    response = self._authenticator._post(url, **data)
  File "/home/admin/project/env/lib/python3.5/site-packages/prawcore/auth.py", line 31, in _post
    raise ResponseException(response)
prawcore.exceptions.PrawcoreException: received 400 HTTP response

知道为什么会这样吗? PRAW版本为6.0.0和prawcore 1.0.0。

谢谢

0 个答案:

没有答案