Forums

mongodb on mlab [Errno 111] Connection Refused

Hi,

I've had Python Eve deployed and connected to a MongoDB instance hosted at mLab for some time now. I haven't made any changes but have suddenly started getting errors when the application tries to connect to MongoDB. Below is the error logged.

2016-12-19 13:32:34,137 :Exception on /quiz [GET]
Traceback (most recent call last):
  File "/home/agroene/.virtualenvs/myvirtualenv/lib/python3.5/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/agroene/.virtualenvs/myvirtualenv/lib/python3.5/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/agroene/.virtualenvs/myvirtualenv/lib/python3.5/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/agroene/.virtualenvs/myvirtualenv/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/home/agroene/.virtualenvs/myvirtualenv/lib/python3.5/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/agroene/.virtualenvs/myvirtualenv/lib/python3.5/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/agroene/.virtualenvs/myvirtualenv/lib/python3.5/site-packages/eve/endpoints.py", line 54, in collections_endpoint
    response = get(resource, lookup)
  File "/home/agroene/.virtualenvs/myvirtualenv/lib/python3.5/site-packages/eve/methods/common.py", line 242, in rate_limited
    return f(*args, **kwargs)
  File "/home/agroene/.virtualenvs/myvirtualenv/lib/python3.5/site-packages/eve/auth.py", line 79, in decorated
    return f(*args, **kwargs)
  File "/home/agroene/.virtualenvs/myvirtualenv/lib/python3.5/site-packages/eve/methods/common.py", line 949, in decorated
    r = f(resource, **combined_args)
  File "/home/agroene/.virtualenvs/myvirtualenv/lib/python3.5/site-packages/eve/methods/get.py", line 101, in get
    cursor = app.data.find(resource, req, lookup)
  File "/home/agroene/.virtualenvs/myvirtualenv/lib/python3.5/site-packages/eve/io/mongo/mongo.py", line 259, in find
    return self.pymongo(resource).db[datasource].find(**args)
  File "/home/agroene/.virtualenvs/myvirtualenv/lib/python3.5/site-packages/eve/io/mongo/mongo.py", line 854, in pymongo
    self.driver[px] = PyMongo(self.app, px)
  File "/home/agroene/.virtualenvs/myvirtualenv/lib/python3.5/site-packages/flask_pymongo/__init__.py", line 97, in __init__
    self.init_app(app, config_prefix)
  File "/home/agroene/.virtualenvs/myvirtualenv/lib/python3.5/site-packages/flask_pymongo/__init__.py", line 253, in init_app
    db.authenticate(username, password)
  File "/home/agroene/.virtualenvs/myvirtualenv/lib/python3.5/site-packages/pymongo/database.py", line 1018, in authenticate
    connect=True)
  File "/home/agroene/.virtualenvs/myvirtualenv/lib/python3.5/site-packages/pymongo/mongo_client.py", line 439, in _cache_credentials
    writable_preferred_server_selector)
  File "/home/agroene/.virtualenvs/myvirtualenv/lib/python3.5/site-packages/pymongo/topology.py", line 210, in select_server
    address))
  File "/home/agroene/.virtualenvs/myvirtualenv/lib/python3.5/site-packages/pymongo/topology.py", line 186, in select_servers
    self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: ds027345.mlab.com:27345: [Errno 111] Connection refused

I'm still able to connect to the database using other tools, so the issue seems to be with the Web App. Can anybody assist?

Free accounts on PythonAnywhere only have HTTP and HTTPS access to sites on our whitelist. MongoDB doesn't use HTTP or HTTPS, so it should never have worked from free accounts -- it looks like there were a few cases (specifically, MLab instances that happened to be in the same data center as our servers) where that wasn't enforced properly, but our most recent system update has closed that.

If you want to use MLab from PythonAnywhere, your best option is to upgrade to a paid account -- the cheapest $5/month one will work fine.

Here's a help page about MongoDB on PythonAnywhere that hopefully will be useful for anyone with questions about this in the future. Any suggestions for extra stuff we should put on there much appreciated!