Forums

SocketError when using PRAW

I'm attempting to use a python script to post a submission to reddit using PRAW. The script works locally, but throws the following error on PA. Any ideas? Traceback looks like:

Traceback (most recent call last): File "/home/bobbyllama/3DS_Noob_Thread_Bot.py", line 34, in <module>
main()
File "/home/bobbyllama/3DS_Noob_Thread_Bot.py", line 31, in main
PostThread()
File "/home/bobbyllama/3DS_Noob_Thread_Bot.py", line 26, in PostThread
Interface.login(BotName, BotPassword)
File "/home/bobbyllama/.local/lib/python2.7/site-packages/praw/init.py", line 1099, in login
self.request_json(self.config['login'], data=data)
File "/home/bobbyllama/.local/lib/python2.7/site-packages/praw/decorators.py", line 95, in wrapped
return_value = function(reddit_session, args, kwargs)
File "/home/bobbyllama/.local/lib/python2.7/site-packages/praw/init.py", line 468, in request_json
response = self._request(url, params, data)
File "/home/bobbyllama/.local/lib/python2.7/site-packages/praw/init.py", line 341, in _request
response = handle_redirect()
File "/home/bobbyllama/.local/lib/python2.7/site-packages/praw/init.py", line 314, in handle_redirect
timeout=timeout,
kwargs)
File "/home/bobbyllama/.local/lib/python2.7/site-packages/praw/handlers.py", line 135, in wrapped
result = function(cls,
kwargs)
File "/home/bobbyllama/.local/lib/python2.7/site-packages/praw/handlers.py", line 54, in wrapped
return function(cls,
kwargs)
File "/home/bobbyllama/.local/lib/python2.7/site-packages/praw/handlers.py", line 90, in request
allow_redirects=False)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 460, in send
r = adapter.send(request,
*kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 246, in send
raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='www.reddit.com', port=80): Max retries exceeded with url: /api/login/.json (Caused by <class 'so cket.error'>: [Errno 111] Connection refused)

Since reddit.com is on the whitelist then as far as I can tell that should work fine. I suggest trying again periodically in case the proxy server is having issues, similar to this one.

The proxy server looks fine, and I can see requests for reddit.com going through OK. Perhaps they're rate-limiting us from time to time?

I'm assuming that there's an ICMP "destination unreachable" coming back to result in the "connection refused" message in the backtrace above. It would be quite rude for Reddit to send ICMP errors in response to being rate-limited - even a relatively dumb load-balancer should be able to send back a static 503 response, preferably with a Retry-After header.

I'm not saying they're not doing that - just that it would be quite rude on their part! (^_^)

As an aside, I've failed to trigger any rate-limiting by some not-too-aggressive methods (NOT running on PA, I hasten to add!), so if they are doing that then either it's a manually-imposed thing, or the bar is quite high for triggering it.

@bobbyllama: Have you seen any of your requests work, or have you got an error every single time?

It looks like everything in your account is as it should be for reddit to be contactable. Could you try a wget in a new bash console?

Thanks for the replies, all. Sorry I forgot about this thread for a few days. Getting ready to move into a new apartment next week and it completely slipped my mind.

@Cartroo: This script has not once run on PA. It works like a charm locally, however.

@glenn: Sure can! Results as follows:

23:21 ~ $ wget http://www.reddit.com                                                                                                                          
--2013-05-23 23:21:22--  http://www.reddit.com/
Resolving proxy.server... 10.93.19.94
Connecting to proxy.server|10.93.19.94|:3128... connected.
Proxy request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `index.html'

    [ <=>                                                                                                                 ] 138,662     --.-K/s   in 0.005s

2013-05-23 23:21:23 (29.2 MB/s) - `index.html' saved [138662]

@bobbyllama did this get resolved? I'm having the same issue.

@mikenon Nope. The script continues to run locally, but fails to run on PA.

Somebody else asked about this a few days ago. It looks like PRAW doesn't recognise the proxy setting. You could try and hack a fix yourself, or report a bug against their project...

https://www.pythonanywhere.com/forums/topic/665/