praw-dev / praw

PRAW, an acronym for "Python Reddit API Wrapper", is a python package that allows for simple access to Reddit's API.
http://praw.readthedocs.io/
BSD 2-Clause "Simplified" License
3.5k stars 458 forks source link

Not using proxy correctly? #237

Closed SurvivalOfTheBravest closed 11 years ago

SurvivalOfTheBravest commented 11 years ago

I'm trying to run a Reddit bot on https://www.pythonanywhere.com. When I try to connect to Reddit, I get the following:

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

This issue is raised perennially on the Pythonanywhere forum, because it tends to occur and resolve sporadically without apparent reason, but the folks over there keep saying it's a bug with PRAW (https://www.pythonanywhere.com/forums/topic/665/#id_post_5802). I don't know if that's true, but maybe you'd know.

Damgaard commented 11 years ago

The problem is not with PRAW. We don't deal with sockets or other low-level internet infrastructure. We use the library requests to actually send and receive the bits.

The issue has already been reported in the request repo. kennethreitz/requests#1218 and a PR that fixes the issue has been made. Problem is that it is backwards - incompatible, meaning a major version update is necessary. I'll watch requests 2.0 thread and when they deploy a never version, then PRAW can update the version required of requests to min 2.0

You can checkout the above issue and it's links for potential work arounds as well as this potential solution I stumbled across.