PRAW Connection refused


I'm having trouble reaching reddit with PRAW. There are a couple other threads with similar problems SocketError when using PRAW and Did something change last night?.... I'm able to wget the same endpoint using the same user-agent.

Traceback (most recent call last):
  File "", line 7, in <module>
    for submission in subreddit.get_hot(limit=5):
  File "/home/mikenon/.local/lib/python2.7/site-packages/praw/", line 434, in get_content
    page_data = self.request_json(url, params=params)
  File "/home/mikenon/.local/lib/python2.7/site-packages/praw/", line 95, in wrapped
    return_value = function(reddit_session, *args, **kwargs)
  File "/home/mikenon/.local/lib/python2.7/site-packages/praw/", line 469, in request_json
    response = self._request(url, params, data)
  File "/home/mikenon/.local/lib/python2.7/site-packages/praw/", line 342, in _request
    response = handle_redirect()
  File "/home/mikenon/.local/lib/python2.7/site-packages/praw/", line 315, in handle_redirect
    timeout=timeout, **kwargs)
  File "/home/mikenon/.local/lib/python2.7/site-packages/praw/", line 135, in wrapped
    result = function(cls, **kwargs)
  File "/home/mikenon/.local/lib/python2.7/site-packages/praw/", line 54, in wrapped
    return function(cls, **kwargs)
  File "/home/mikenon/.local/lib/python2.7/site-packages/praw/", line 90, in request
  File "/usr/local/lib/python2.7/site-packages/requests/", line 460, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/", line 246, in send
    raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='', port=80): Max retries exceeded with url: /r/pics/.json?limit=2 (Caused by <class 'socket.error'>: [Errno 111] Connection refused)`

The script is pretty basic:

import praw
from pprint import pprint
reddit = praw.Reddit(user_agent='testing praw /u/mikenon')
subreddit = reddit.get_subreddit('pics')
for submission in subreddit.get_hot(limit=2):
    for comment in praw.helpers.flatten_tree(submission.comments):

Is it a proxy issue on PA's end? Or is there something I can fix?

Thank you

How does it behave when you're not using PRAW? The proxy server is working fine and showing a lot of hits against reddit. Try using wget or resuests and check the results. Perhaps there's an issue with PRAW.


Yeah, wget and Requests work. I was under the impression that PRAW was working for people here, though? PRAW has a config option for setting a proxy to use, can/should I put PA's proxy there? Is it just http://proxy.server/ ?


I'm thinking the proxy is the speed bump here. Here's what I've scraped up to do some debugging:

import praw
import requests
import logging
import httplib
httplib.HTTPConnection.debuglevel = 1
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.propagate = True

# Works
print 'Making basic Requests get'

# Doesn't work
print '\n\nImporting PRAW and requesting submissions'
r = praw.Reddit(user_agent='Trying out PRAW on PythonAnywhere',site_name='reddit_nossl')
submissions = r.get_subreddit('opensource').get_hot(limit=5)
print [str(x) for x in submissions]

Logs for requests.get(url) show

INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): proxy.server

While requests from PRAW show

INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1):

So it would seem there ought to be a way to coerce PRAW into using the proxy.

May be worth raising it as a bug against PRAW, or as @PSBCommentBot says, try and hack in a fix yourself...

I'm getting the same error. Does this have to do with a non-paid account? (limits, etc)

It's really a bug in PRAW -- it doesn't play nicely with the proxy we use for free accounts. So it will work fine with a paid account, which doesn't use a proxy.

Was something changed in the backend recently? I'm running a continuous script that was working earlier today, which is now getting this error (although I never restarted it between then and now).

Edit: It looks like PRAW is indeed using the proxy (whatever that means) but it's still giving an error. Traceback:

Traceback (most recent call last):
  File "", line 154, in <module>
    r.login(username, password)
  File "/home/sns/.local/lib/python2.7/site-packages/praw/", line 906, in login
    self.request_json(self.config['login'], data=data)
  File "/home/sns/.local/lib/python2.7/site-packages/praw/", line 223, in error_check
    return_value = function(cls, *args, **kwargs)
  File "/home/sns/.local/lib/python2.7/site-packages/praw/", line 407, in request_json
    response = self._request(url, params, data)
  File "/home/sns/.local/lib/python2.7/site-packages/praw/", line 294, in _request
  File "/home/sns/.local/lib/python2.7/site-packages/praw/", line 64, in __call__
    result = self.function(reddit_session, url, *args, **kwargs)
  File "/home/sns/.local/lib/python2.7/site-packages/praw/", line 167, in __call__
    return self.function(*args, **kwargs)
  File "/home/sns/.local/lib/python2.7/site-packages/praw/", line 137, in _request
    allow_redirects=False, auth=auth)
  File "/home/sns/.local/lib/python2.7/site-packages/requests/", line 377, in post
    return self.request('POST', url, data=data, **kwargs)
  File "/home/sns/.local/lib/python2.7/site-packages/requests/", line 335, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/sns/.local/lib/python2.7/site-packages/requests/", line 438, in send
    r = adapter.send(request, **kwargs)
  File "/home/sns/.local/lib/python2.7/site-packages/requests/", line 327, in send
    raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='proxy.server', port=3128): Max retri
es exceeded with url: (Caused by <class 'socket.error'>: [Er
rno 111] Connection refused)

I've bounced the proxy server, just in case. But if it's still not working, it's probably because the PRAW library is simply incompatible with proxies -- there are several outstanding bugs in, eg, the rquests library and urllib3 which are know to cause problems with HTTPS and proxies.

For now the best solution is to upgrade. If you switch to a paid account and can't get it to work, we'll happily give you a full refund...

Everything seems to work now, more smoothly than before even. Thanks!

Now I know, as a free user I'm not really "entitled" to anything, but it does seem a little strange to break previously-working functions of the free accounts and then recommend upgrading as a solution, just saying...

Anyone interested in this should track the issue on praw's github...