0

I'm trying to get a Flask app running with Apache via WSGI but am getting the following error flagged in the Apache logs when I try to connect to the server. At a bit of a loss. Appreciate any pointers. Thanks!

mod_wsgi (pid=7884): Target WSGI script '/var/www/tracker/tracker/tracker.wsgi' cannot be loaded as Python module.

mod_wsgi (pid=7884): Exception occurred processing WSGI script '/var/www/tracker/tracker/tracker.wsgi'.

 Traceback (most recent call last):
   File "/var/www/tracker/tracker/tracker.wsgi", line 3, in <module>
     from tracker import app as application
   File "/var/www/tracker/tracker/tracker.py", line 3, in <module>
     from flask_mongoengine import MongoEngine
   File "/var/www/tracker/lib/python3.5/site-packages/flask_mongoengine/__init__.py", line 6, in <module>
     import mongoengine
   File "/var/www/tracker/lib/python3.5/site-packages/mongoengine/__init__.py", line 2, in <module>
     from mongoengine import connection
ImportError: cannot import name connection
Omar Einea
  • 2,478
  • 7
  • 23
  • 35
KirkyJ
  • 5
  • 2

2 Answers2

0

Mongoengine doesn't have a "connection" method or object. If you want to connect to database, please use "connect(%database_name%)".

Source: http://docs.mongoengine.org/guide/connecting.html#connecting-to-mongodb

  • Thanks for the feedback. I understand what you're saying but the code runs perfectly fine when I run it locally, its only when I move it to the hosting provider environment that I see this error. Also, from the error it looks like its complaining that the import error is coming from an import coded in __init__.py from the mongoengine package. – KirkyJ Jan 29 '18 at 08:32
0

OK. So a bit more troubleshooting and seems that the import error was bogus and instead it looks like I was hitting a an issue with the Apache2 WSGI plugin. I'd wrongly installed libapache2-mod-wsgi and as I'm using Python 3.5 I should have installed libapache2-mod-wsgi-py3.

More details are at:

Error using mod_wsgi, Django and MongoEngine

KirkyJ
  • 5
  • 2