5

I am trying to make a long-running Python script that periodically queries Reddit for new submissions/comments using PRAW 4.4.0 and at first I initialize the object like this:

redditClient = praw.Reddit(
    client_id=constants.REDDIT_CLIENT_ID,
    client_secret=constants.REDDIT_CLIENT_SECRET,
    user_agent=constants.REDDIT_USER_AGENT
)

After a period of time I am receiving the following error:

error with request ('Connection aborted.', error(104, 'Connection reset by peer'))

My guess is that this happens because I am keeping the connection open, but I didn't find a way how to close it. Can you help me figure out how to resolve this issue?

finefoot
  • 9,914
  • 7
  • 59
  • 102
Dorin
  • 2,167
  • 4
  • 20
  • 32
  • 1
    Why can't you just [retry](https://pypi.python.org/pypi/retry/0.9.2) when a 104 is received? And when a 500 is received, too, for that matter. – 9000 Mar 02 '17 at 16:01
  • If praw is doing connection caching (but hot handling stale connections), you'd see this. @9000's approach is right, though it might be worth digging through praw to see if this is what it's doing. – David Ehrmann Mar 02 '17 at 16:04

1 Answers1

0

While you can retry these requests yourself, it really is something that PRAW should internally handle, and in fact the latest development version of prawcore (PRAW's internal library) supports retrying requests that fail in this way.

To experiment with this development version update your prawcore via:

pip install -U https://github.com/praw-dev/prawcore/zipball/master
bboe
  • 4,092
  • 3
  • 29
  • 39