Unable to run run.py (**user_info) SyntaxError: invalid syntax

when i run python run.py OR pytest -m connection it gives me error:

Traceback (most recent call last):
File “/usr/lib/python2.7/dist-packages/_pytest/config.py”, line 373, in _importconftest
mod = conftestpath.pyimport()
File “/usr/lib/python2.7/dist-packages/py/_path/local.py”, line 662, in pyimport
File "/usr/lib/python2.7/dist-packages/pytest/assertion/rewrite.py", line 211, in load_module
(co, mod.dict)
File "/usr/lib/python2.7/dist-packages/py/builtin.py", line 221, in exec
exec2(obj, globals, locals)
File “”, line 7, in exec2
File “/home/user/Desktop/mflix-python/tests/conftest.py”, line 2, in
from mflix.factory import create_app
File “/home/user/Desktop/mflix-python/mflix/factory.py”, line 12, in
from mflix.api.movies import movies_api_v1
File “/home/user/Desktop/mflix-python/mflix/api/movies.py”, line 243
SyntaxError: invalid syntax
ERROR: could not load /home/user/Desktop/mflix-python/tests/conftest.py

i’ve run “pip install -r requirements.txt” with no errors

I’ve tried on ubuntu 17.10 and Mac OS ver 10.13.6, using python 2.7 and 3.6.3 but still the error persists…

I’ve followed the instructions and this is my .ini content:

SECRET_KEY = super_secret_key_you_should_change
MFLIX_DB_URI = mongodb+srv://m220student:m220password@(my_cluster_URI)/mflix

SECRET_KEY = super_secret_testing_key
MFLIX_DB_URI = mongodb+srv://m220student:m220password(my_cluster_URI)/mflix

seeking help, anyone… appreciate it…

Hello Ferdinand_14298,

I’m sorry to hear you’ve had this issue. Thanks for doing some troubleshooting already.

I have a few ideas:

  1. Did you forget a “@” in your TEST URI? Looks like you have it in PROD.
  2. This might seem elementary, but have you tried uninstalling and reinstalling pytest? Like so:
    pip uninstall pytest
    pip install pytest
  3. Also, are you using Conda? As a last resort, starting over with a new environment may help.

Let me know if this helps. And please post in the forums if you solve it another way :smiley:!


Hi Matt,

Thank you for the reply.

  1. I typed wrongly on the post above, yes there is @ sign in my local [TEST]
  2. I’ve tried your way but still the problem persist
  3. No i didn’t use Conda or Virtual_env, i guess i will try the “starting over with new environment” but it’ll take some time for me.

I guess i’ve to forego the Ticket assignments first and try to troubleshoot the error.

Hi Ferdinand_14298,

That’s frustrating, let’s see if we can’t solve this thing.

Just to confirm, you can connect through the mongo shell? E.g. mongo <your-uri-string> will connect you to the Atlas database?

If you can’t connect through the shell, it might be because the end of your string has /mflix, which means your m220student user is authenticating against the mflix database. If you remove it, the user will authenticate against the admin database instead.

In terms of starting a new environment, Conda is the safest way to do this, because then you don’t have to reconfigure your host machine’s Python settings. And it shouldn’t take too long - creating a new environment and installing the requirements should take about 5-10 minutes.

Hopefully you can solve this in time to complete the tickets!


It looks like the error is from this line:

db.command({'connectionStatus': 1}).get('authInfo').get('authenticatedUserRoles')[0]

Can you try running this line from the Mongo shell?

Hi Matt,

Thank you for your effort, appreciate it.

  1. Yes i can connect to my atlas database (m220 cluster - mflix database) using mongo shell.
    i can connect without problem using:
  • mongo “mongodb+srv://<my_m220_cluster>.mongodb.net/” --username m220student
  • mongo “mongodb+srv://<my_m220_cluster>.mongodb.net/test” --username m220student
  • mongo “mongodb+srv://<my_m220_cluster>.mongodb.net/mflix” --username m220student
  1. I’ve already populated my m220 with mflix database without problem ( mongorestore --drop --gzip --uri mongodb+srv://m220student:m220password<YOUR_CLUSTER_URI>)

  2. I’ve tried your “db.command({…” as specified above in my mongo shell, here is the result:
    > db.command({‘connectionStatus’: 1}).get(‘authInfo’).get(‘authenticatedUserRoles’)[0]
    2018-09-26T02:01:00.686+0800 E QUERY [js] TypeError: db.command is not a function :

am able to execute “db.enableFreeMonitoring()” in my mongo shell without problem.

  1. I’ve tried using virtualenv and followed step by step from Lecture: README but the same error still persist (the same error as my first post above), went back to square one.

  2. I have not tried Conda yet, I’ll try now and i’ll see how it goes.

Sorry about that, I pasted the command in Pymongo. Here it is in Mongo shell syntax:

db.runCommand({'connectionStatus': 1})

This seems to be the same command that is failing against your Atlas cluster. Can you tell me what the output is?

Hello, It seems to be an indent problem in db.py on line 274 except is wrongly indented. You need also to fix indentation on line 284.


It looks like you’re running it on python2.7. I had the same problem (using conda) and was caused by the python version.
Once you run it with python3 you may then find a dependency error like the one from this other post:

I think that is caused by the order of the Python version in your PATH. I had to add Python3 in the System Variable PATH with Python3 (in my case Anaconda) before Python2 version. Once you change that, close and open a new prompt and run again pip to install the dependencies (this time will get the right version):

pip install -r requirements.txt

If you get any error there, run:

python -m pip install --upgrade pip
and again:
pip install -r requirements.txt

Then… you will get the indentation error spotted by Bleu39 in …\mflix\db.py#274

I hope it helps!


I just commented out that line, then it worked for me!



Bleu39 has the answer. I want to give more details about it.
To correct the identation error you must to be sure that the try - except are in the same line:

def get_movie(id):
except (StopIteration) as _:

Thanks Bleu39

This helped me to get pytest running correctly, but now I have two failing tests.

Thanks! Bleu39 I was getting that error. I am using Anaconda Environment on Windows 10. I corrected the Indent of except and it worked.

Am getting same error but the above issue is a bit different from mine.

C:\university\m220\mflix-python>python run.py
Traceback (most recent call last):
File “run.py”, line 1, in
from mflix.factory import create_app
File “C:\university\m220\mflix-python\mflix\factory.py”, line 12, in
from mflix.api.movies import movies_api_v1
File “C:\university\m220\mflix-python\mflix\api\movies.py”, line 243
SyntaxError: invalid syntax

I have checked the movies.py and found it as below:
_WriteConcern__document.get(‘wtimeout’, ‘0’),

should i remove the double extericks?
this is because the instruction said we should not tamper with this file.

Kindly help me

am getting same error as below:

C:\university\m220\mflix-python>python run.py
Traceback (most recent call last):
File “run.py”, line 1, in
from mflix.factory import create_app
File “C:\university\m220\mflix-python\mflix\factory.py”, line 12, in
from mflix.api.movies import movies_api_v1
File “C:\university\m220\mflix-python\mflix\api\movies.py”, line 243
SyntaxError: invalid syntax

MongoDB Enterprise mflix-shard-0:PRIMARY> show dbs
admin 0.000GB
local 2.787GB
mflix 0.009GB
MongoDB Enterprise mflix-shard-0:PRIMARY> db.command({‘connectionStatus’: 1}).get(‘authInfo’).get(‘authenticatedUserRoles’)[0]
2018-10-20T08:13:46.293+0100 E QUERY [js] TypeError: db.command is not a function :
MongoDB Enterprise mflix-shard-0:PRIMARY> db.runCommand({‘connectionStatus’: 1})
“authInfo” : {
“authenticatedUsers” : [
“user” : “m220student”,
“db” : “admin”
“authenticatedUserRoles” : [
“role” : “readWriteAnyDatabase”,
“db” : “admin”
“ok” : 1
MongoDB Enterprise mflix-shard-0:PRIMARY>

Kindly assist me to resolve it and proceed with the lesson.
Your help is appreciated.

Note i have sorted this out.

i had python 2.7 32bit installed on my laptop. i downloaded the latest python 3.7 but it downloaded 32bit again meanwhile my laptop is 64bit. So after installing the python 3.7, when i checked version status(python --version), it is still showing python 2.7.
so google how to download python for 64bit windows, and i followed the steps and downloaded and installed the python for 64bit windows. check then restart my laptop and check status again and it showed the latest version installed which is python 3.7.
Then i ran the command to install the requirements for the course(pip install -r requirements.txt).
Then, i ran the python run.py and it worked fine this time without error.

c:\university\m220\mflix-python>python run.py

  • Restarting with stat
  • Debugger is active!
  • Debugger PIN: 321-451-220
  • Running on http://xxx.x.x.x:xxxx/ (Press CTRL+C to quit) - - [21/Oct/2018 00:55:51] “GET / HTTP/1.1” 200 - - - [21/Oct/2018 00:55:51] “GET /static/css/main.61f16bdd.css HTTP/1.1” 200 - - - [21/Oct/2018 00:55:51] “GET /static/js/main.a4491d28.js HTTP/1.1” 200 - - - [21/Oct/2018 00:56:04] “GET /static/media/mongoleaf.0ebc1843.png HTTP/1.1” 200 - - - [21/Oct/2018 00:56:04] “GET /service-worker.js HTTP/1.1” 200 - - - [21/Oct/2018 00:56:04] “GET /favicon.ico HTTP/1.1” 200 - - - [21/Oct/2018 00:56:17] “GET /api/v1/movies/ HTTP/1.1” 200 - - - [21/Oct/2018 00:59:56] “GET /favicon.ico HTTP/1.1” 200 - - - [21/Oct/2018 01:00:32] “GET /favicon.ico HTTP/1.1” 200 - - - [21/Oct/2018 01:00:32] “OPTIONS /api/v1/user/login HTTP/1.1” 200 - - - [21/Oct/2018 01:00:38] “GET /api/v1/movies/ HTTP/1.1” 200 - - - [21/Oct/2018 01:00:44] “POST /api/v1/user/login HTTP/1.1” 401 -

thanks all for your contribution


Hi PaulNewman,

Thanks for the note, I’m glad to hear you’ve gotten past this issue. For future reference, most of the MongoDB University courses will require a 64-bit version of Python and the Mongo server.


Hi everyone, i have the same problem PauNewman, but I cant resolved. When I’ll try running pytest -m connection this problem happens:

E File “/media/sf_public_html/mflix-python/mflix/api/movies.py”, line 233
E **user_info
E ^
E SyntaxError: invalid syntax

I try in 3 computers, Fedora, Ubuntu,CentOS. Everyone happen this error.

This is my .ini

SECRET_KEY = super_secret_key_you_should_change
MFLIX_DB_URI = mongodb+srv://m220student:m220password@mongodb+srv://python3-aula-ugv6i.mongodb.net/test

SECRET_KEY = super_secret_testing_key
MFLIX_DB_URI = mongodb+srv://python3-aula-ugv6i.mongodb.net/test

I have the same problem, but i’m using MacOsx 10.14.3, anaconda 3 and python 3.6.
the connections with the DB is OK.