PythonAnywhere Forums

Mongodb Error

https://stackoverflow.com/questions/41759254/pythonanywhere-flask-500-internal-whenever-post

I am having this same issue, but I have a paid account. Any solutions?

Make sure that your mongo instance is visible to the internet. Also, search the forums - there are a number of people that have worked through various issues with mongo and some of them may apply to you.

The mongo instance is visible on the internet. Works fine with the development environment. Everything I have seen with this issue points to not having a paid account, which I do. Is there any assistance you can offer?

We don't interfere in any way with outgoing network for paid accounts.

If you're running the code in a console, you will need to do it in a new console (new since the upgrade). If you're running it in a webapp, you'll need to reload the web app after the upgrade.

Otherwise search the forums for more mongo-specific info.

Both the console and the webapp have been restarted.

I have searched the forums and there is nothing that addresses my connection problem. The Stack Overflow link talks directly to the issue.

Can you please provide some documentation about how to connect to MongoDB from PA?

Connecting to MongoDB from a PythonAnywhere paid account should be exactly the same as connecting from, say, your own computer. At a low level, what's happening is identical -- packets go from our servers to the Mongo instance and back again just the same way as they would from your machine.

But clearly if you can connect from your own machine but not from our site, there's something different happening, perhaps non-obviously.

A few questions:

  • Are you, like the person in the Stack Overflow post, trying to connect from a Flask app? Or some other kind of web framework?
  • If it's from a web framework, can you try connecting from a console to see if that behaves differently (if you haven't already)?
  • Could you post the exact traceback that you're getting? There might be non-obvious differences between the one that person is getting and the one are that might help debug?

Nice site!

Here is my actual error:

2017-09-11 20:50:58,639: /home/jcrowe/.local/lib/python2.7/site-packages/pymongo/topology.py:145: UserWarning: MongoClient opened before fork. Create MongoClient with connect=False, or create client after forking. See PyMongo's documentation for details: http://api.mongodb.org/python/current/faq.html#pymongo-fork-safe>
2017-09-11 20:50:58,639:   "MongoClient opened before fork. Create MongoClient "
2017-09-11 20:51:28,653: Error running WSGI application
2017-09-11 20:51:28,668: ServerSelectionTimeoutError: No servers found yet
2017-09-11 20:51:28,669:   File "/home/jcrowe/.local/lib/python2.7/site-packages/flask/app.py", line 2000, in __call__
2017-09-11 20:51:28,669:     return self.wsgi_app(environ, start_response)
2017-09-11 20:51:28,669: 
2017-09-11 20:51:28,669:   File "/home/jcrowe/.local/lib/python2.7/site-packages/flask/app.py", line 1991, in wsgi_app
2017-09-11 20:51:28,669:     response = self.make_response(self.handle_exception(e))
2017-09-11 20:51:28,669: 
2017-09-11 20:51:28,669:   File "/home/jcrowe/.local/lib/python2.7/site-packages/flask/app.py", line 1567, in handle_exception
2017-09-11 20:51:28,670:     reraise(exc_type, exc_value, tb)
2017-09-11 20:51:28,670: 
2017-09-11 20:51:28,670:   File "/home/jcrowe/.local/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
2017-09-11 20:51:28,670:     response = self.full_dispatch_request()
2017-09-11 20:51:28,670: 
2017-09-11 20:51:28,670:   File "/home/jcrowe/.local/lib/python2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
2017-09-11 20:51:28,670:     rv = self.handle_user_exception(e)
2017-09-11 20:51:28,671: 
2017-09-11 20:51:28,671:   File "/home/jcrowe/.local/lib/python2.7/site-packages/flask/app.py", line 1544, in handle_user_exception
2017-09-11 20:51:28,671:     reraise(exc_type, exc_value, tb)
2017-09-11 20:51:28,671: 
2017-09-11 20:51:28,671:   File "/home/jcrowe/.local/lib/python2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
2017-09-11 20:51:28,671:     rv = self.dispatch_request()
2017-09-11 20:51:28,671: 
2017-09-11 20:51:28,671:   File "/home/jcrowe/.local/lib/python2.7/site-packages/flask/app.py", line 1625, in dispatch_request
2017-09-11 20:51:28,672:     return self.view_functions[rule.endpoint](**req.view_args)
2017-09-11 20:51:28,672: 
2017-09-11 20:51:28,672:   File "/home/jcrowe/Amazon_Management_Platform/app/flask_app.py", line 34, in inv
2017-09-11 20:51:28,672:     df = pd.DataFrame([x for x in db.asin_data.find()])
2017-09-11 20:51:28,672: 
2017-09-11 20:51:28,672:   File "/home/jcrowe/.local/lib/python2.7/site-packages/pymongo/cursor.py", line 1114, in next
2017-09-11 20:51:28,672:     if len(self.__data) or self._refresh():
2017-09-11 20:51:28,672: 
2017-09-11 20:51:28,673:   File "/home/jcrowe/.local/lib/python2.7/site-packages/pymongo/cursor.py", line 1036, in _refresh
2017-09-11 20:51:28,673:     self.__collation))
2017-09-11 20:51:28,673: 
2017-09-11 20:51:28,673:   File "/home/jcrowe/.local/lib/python2.7/site-packages/pymongo/cursor.py", line 873, in __send_message
2017-09-11 20:51:28,673:     **kwargs)
2017-09-11 20:51:28,673: 
2017-09-11 20:51:28,673:   File "/home/jcrowe/.local/lib/python2.7/site-packages/pymongo/mongo_client.py", line 888, in _send_message_with_response
2017-09-11 20:51:28,673:     server = topology.select_server(selector)
2017-09-11 20:51:28,674: 
2017-09-11 20:51:28,674:   File "/home/jcrowe/.local/lib/python2.7/site-packages/pymongo/topology.py", line 214, in select_server
2017-09-11 20:51:28,674:     address))
2017-09-11 20:51:28,674: 
2017-09-11 20:51:28,674:   File "/home/jcrowe/.local/lib/python2.7/site-packages/pymongo/topology.py", line 189, in select_servers
2017-09-11 20:51:28,674:     self._error_message(selector))

I have not run the connection from a bash prompt yet, but the error seems to talk to the idea of forking being the problem.

I am trying to connect from a flask app.

Hi there, we don't support threads in our web apps, and I think the latest version of the pymongo client library tries to force you to use threads. Try setting maxPoolSize=1 ?

I ran a quick test in the console and didn't have any problems. The code ran as expected.

I have changed the maxPoolSize to 1. That didn't change anything.

have you tried googling the error message? eg this thread suggests setting connect=False https://stackoverflow.com/questions/44133435/mongoengine-and-dealing-with-userwarning-mongoclient-opened-before-fork-creat

well... connect=False

Was the first thing I tried and it didn't work.

maxPoolSize=1

Also didn't work.

connect=False, maxPoolSize=1

Does work!

Thanks, Jason

Excellent! Glad you worked it out :-)