Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"[Errno 111] Connection refused" on Pythonanywhere

I am trying to deploy my application on pythonanywhere but I am unable to connect to twitter.

Here is the error that I am getting :-

Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1687, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1360, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1358, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1344, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/btpraasta/btp_raasta/runServer.py", line 178, in remainingRequests
return (str)(getTrend.get_remainingRequests())
File "/home/btpraasta/btp_raasta/python/getTrend.py", line 20, in get_remainingRequests
data = get_json(url)
File "/home/btpraasta/btp_raasta/python/getTrend.py", line 10, in get_json
connection = urllib.urlopen(url, proxies=proxies)
File "/usr/lib/python2.7/urllib.py", line 87, in urlopen
return opener.open(url)
File "/usr/lib/python2.7/urllib.py", line 208, in open
return getattr(self, name)(url)
File "/usr/lib/python2.7/urllib.py", line 437, in open_https
h.endheaders(data)
File "/usr/lib/python2.7/httplib.py", line 975, in endheaders
self._send_output(message_body)
File "/usr/lib/python2.7/httplib.py", line 835, in _send_output
self.send(msg)
File "/usr/lib/python2.7/httplib.py", line 797, in send
self.connect()
File "/usr/lib/python2.7/httplib.py", line 1178, in connect
self.timeout, self.source_address)
File "/usr/lib/python2.7/socket.py", line 571, in create_connection
raise err
IOError: [Errno socket error] [Errno 111] Connection refused

The code I am trying to run is this :-

proxies = {'http': 'http://proxy.server:3128'}
connection = urllib.urlopen(url, proxies=proxies)
data = connection.read()

And I am trying to access the following URL :- 'https://api.twitter.com/1.1/application/rate_limit_status.json'

I have a free account on pythonanywhere and verified that the API is whitelisted and I am using the proxy as described by them here (http://help.pythonanywhere.com/pages/403ForbiddenError).

like image 930
Mrinal Ahlawat Avatar asked Dec 20 '25 23:12

Mrinal Ahlawat


1 Answers

Copying my comment to a proper answer: getting proxies to work with urllib can be tricky. requests is in general much easier to use, and it pulls proxy settings from environment variables. Definitely recommended!

like image 106
Giles Thomas Avatar answered Dec 23 '25 13:12

Giles Thomas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!