SyntaxError: invalid syntax

(mflix) niraj@ALIPLR2070:/mnt/d/Downloads/Personal/Mongo-Certs/M220P-Python-MongoDB-Course/mflix-python$ python run.py
Traceback (most recent call last):
File “run.py”, line 1, in
from mflix.factory import create_app
File “/mnt/d/Downloads/Personal/Mongo-Certs/M220P-Python-MongoDB-Course/mflix-python/mflix/factory.py”, line 12, in
from mflix.api.movies import movies_api_v1
File “/mnt/d/Downloads/Personal/Mongo-Certs/M220P-Python-MongoDB-Course/mflix-python/mflix/api/movies.py”, line 233
**user_info
^
SyntaxError: invalid syntax

Please help me to make this code running! I’m new to Python.

The code looks like

@movies_api_v1.route(’/config-options’, methods=[“GET”])
def get_conn_pool_size():
try:
(pool_size, w_concern, user_info) = get_configuration()
return jsonify({
‘pool_size’: pool_size,
‘wtimeout’: w_concern._WriteConcern__document.get(‘wtimeout’, ‘0’),
**user_info
}), 200
except Exception as e:
return jsonify({‘error’: str(e)}), 400

looks like your .ini file cannot be read correctly…

Alright! How do I fix that?

Find the error and correct it. Mine looks like this:

[PROD]
SECRET_KEY = super_secret_key_you_should_change
MFLIX_DB_URI = mongodb+srv://m220student:m220password@*your_cluster*.mongodb.net
MFLIX_NS = sample_mflix

[TEST]
SECRET_KEY = super_secret_testing_key
MFLIX_DB_URI = mongodb+srv://m220student:m220password@*your_cluster*.mongodb.net
MFLIX_NS = sample_mflix

Of course *your_cluster* is unique for you.

I don’t have any issues to connect to the cluster; I can connect it without any error message; The issue comes in

mflix-python/mflix/api/movies.py file at line 233
**user_info

this is not readable

Why? And what can I replace this with to make it work?

If the cluster is not connected then the application will not scan any file further down the line. Please let me know if my assumption is wrong!

Hi @nadhikary,

Please check all the changes you have made in the .ini file. Also, make sure you have imported the sample data before going further.

Please share the changes in .ini file here so that we can debug that.

As excited as we are here to help you through the course, but this course will require course taker to have Python knowledge before hand, as our main focus here is to teach on how to integrate MongoDB with Python.

Kanika

Ticket: Connection

Rename this file to .ini after filling in your MFLIX_DB_URI and your SECRET_KEY

Do not surround the URI with quotes

[PROD]
SECRET_KEY = super_secret_key_you_should_change
MFLIX_DB_URI = mongodb+srv://m220student:m220password@mflix-ypsna.mongodb.net/test?retryWrites=true&w=majority
MFLIX_NS = sample_mflix

[TEST]
SECRET_KEY = super_secret_testing_key
MFLIX_DB_URI = your_testing_db_uri (can be the same as Atlas, or a local MongoDB database)
MFLIX_NS = sample_mflix
~

this is the content of my .ini file

And i have imported the data successfully

(mflix) niraj@ALIPLR2070:/mnt/d/Downloads/Personal/Mongo-Certs/M220P-Python-MongoDB-Course/mflix-python$ mongorestore --drop --gzip --uri mongodb+srv://m220student:m220password@mflix-ypsna.mongodb.net/test data
2019-09-22T21:03:27.804+0530 preparing collections to restore from
2019-09-22T21:03:27.870+0530 reading metadata for sample_mflix.movies from data/sample_mflix/movies.metadata.json.gz
2019-09-22T21:03:27.959+0530 restoring sample_mflix.movies from data/sample_mflix/movies.bson.gz
2019-09-22T21:03:28.118+0530 reading metadata for sample_mflix.users from data/sample_mflix/users.metadata.json.gz
2019-09-22T21:03:28.171+0530 reading metadata for sample_mflix.comments from data/sample_mflix/comments.metadata.json.gz
2019-09-22T21:03:28.173+0530 reading metadata for sample_mflix.theaters from data/sample_mflix/theaters.metadata.json.gz
2019-09-22T21:03:28.199+0530 restoring sample_mflix.users from data/sample_mflix/users.bson.gz
2019-09-22T21:03:28.300+0530 restoring sample_mflix.comments from data/sample_mflix/comments.bson.gz
2019-09-22T21:03:28.318+0530 restoring sample_mflix.theaters from data/sample_mflix/theaters.bson.gz
2019-09-22T21:03:29.702+0530 restoring indexes for collection sample_mflix.users from metadata
2019-09-22T21:03:29.757+0530 finished restoring sample_mflix.users (183 documents)
2019-09-22T21:03:29.885+0530 reading metadata for sample_mflix.sessions from data/sample_mflix/sessions.metadata.json.gz
2019-09-22T21:03:30.024+0530 restoring sample_mflix.sessions from data/sample_mflix/sessions.bson.gz
2019-09-22T21:03:30.161+0530 restoring indexes for collection sample_mflix.sessions from metadata
2019-09-22T21:03:30.306+0530 finished restoring sample_mflix.sessions (1 document)
2019-09-22T21:03:30.400+0530 [##…] sample_mflix.movies 1.05MB/11.8MB (8.9%)
2019-09-22T21:03:30.401+0530 […] sample_mflix.comments 80.0KB/3.62MB (2.2%)
2019-09-22T21:03:30.402+0530 [################…] sample_mflix.theaters 56.0KB/79.6KB (70.3%)
2019-09-22T21:03:30.403+0530
2019-09-22T21:03:31.403+0530 [########################] sample_mflix.theaters 79.6KB/79.6KB (100.0%)
2019-09-22T21:03:31.403+0530 restoring indexes for collection sample_mflix.theaters from metadata
2019-09-22T21:03:31.517+0530 finished restoring sample_mflix.theaters (1564 documents)
2019-09-22T21:03:33.400+0530 [###…] sample_mflix.movies 1.54MB/11.8MB (13.1%)
2019-09-22T21:03:33.401+0530 [##…] sample_mflix.comments 376KB/3.62MB (10.2%)
2019-09-22T21:03:33.402+0530
2019-09-22T21:03:36.400+0530 [####…] sample_mflix.movies 2.02MB/11.8MB (17.2%)
2019-09-22T21:03:36.401+0530 [####…] sample_mflix.comments 740KB/3.62MB (20.0%)
2019-09-22T21:03:36.403+0530
2019-09-22T21:03:39.401+0530 [######…] sample_mflix.movies 2.95MB/11.8MB (25.1%)
2019-09-22T21:03:39.401+0530 [########…] sample_mflix.comments 1.23MB/3.62MB (33.9%)
2019-09-22T21:03:39.402+0530
2019-09-22T21:03:42.400+0530 [######…] sample_mflix.movies 2.95MB/11.8MB (25.1%)
2019-09-22T21:03:42.401+0530 [###########…] sample_mflix.comments 1.73MB/3.62MB (47.8%)
2019-09-22T21:03:42.402+0530
2019-09-22T21:03:45.400+0530 [######…] sample_mflix.movies 3.43MB/11.8MB (29.2%)
2019-09-22T21:03:45.401+0530 [##############…] sample_mflix.comments 2.24MB/3.62MB (61.9%)
2019-09-22T21:03:45.403+0530
2019-09-22T21:03:48.400+0530 [########…] sample_mflix.movies 3.93MB/11.8MB (33.5%)
2019-09-22T21:03:48.401+0530 [##################…] sample_mflix.comments 2.74MB/3.62MB (75.7%)
2019-09-22T21:03:48.402+0530
2019-09-22T21:03:51.401+0530 [#########…] sample_mflix.movies 4.43MB/11.8MB (37.7%)
2019-09-22T21:03:51.401+0530 [#####################…] sample_mflix.comments 3.24MB/3.62MB (89.6%)
2019-09-22T21:03:51.402+0530
2019-09-22T21:03:54.198+0530 [########################] sample_mflix.comments 3.62MB/3.62MB (100.0%)
2019-09-22T21:03:54.199+0530 no indexes to restore
2019-09-22T21:03:54.201+0530 finished restoring sample_mflix.comments (50304 documents)
2019-09-22T21:03:54.400+0530 [##########…] sample_mflix.movies 4.95MB/11.8MB (42.2%)
2019-09-22T21:03:57.400+0530 [############…] sample_mflix.movies 6.04MB/11.8MB (51.4%)
2019-09-22T21:04:00.400+0530 [##############…] sample_mflix.movies 7.11MB/11.8MB (60.5%)
2019-09-22T21:04:03.401+0530 [################…] sample_mflix.movies 8.21MB/11.8MB (69.9%)
2019-09-22T21:04:06.400+0530 [##################…] sample_mflix.movies 9.22MB/11.8MB (78.5%)
2019-09-22T21:04:09.401+0530 [####################…] sample_mflix.movies 10.2MB/11.8MB (86.7%)
2019-09-22T21:04:12.400+0530 [######################…] sample_mflix.movies 11.1MB/11.8MB (94.9%)
2019-09-22T21:04:15.181+0530 [########################] sample_mflix.movies 11.8MB/11.8MB (100.0%)
2019-09-22T21:04:15.182+0530 restoring indexes for collection sample_mflix.movies from metadata
2019-09-22T21:04:20.545+0530 finished restoring sample_mflix.movies (23539 documents)
2019-09-22T21:04:20.546+0530 done

Please change this to the same cluster URI as above.

Kanika

Hi Kanika,
I did as follows

Ticket: Connection

Rename this file to .ini after filling in your MFLIX_DB_URI and your SECRET_KEY

Do not surround the URI with quotes

[PROD]
SECRET_KEY = super_secret_key_you_should_change
MFLIX_DB_URI = mongodb+srv://m220student:m220password@mflix-ypsna.mongodb.net/test?retryWrites=true&w=majority
MFLIX_NS = sample_mflix

[TEST]
SECRET_KEY = super_secret_testing_key
MFLIX_DB_URI = mongodb+srv://m220student:m220password@mflix-ypsna.mongodb.net/test?retryWrites=true&w=majority
MFLIX_NS = sample_mflix

but the result is same after

(mflix) niraj@ALIPLR2070:/mnt/d/Downloads/Personal/Mongo-Certs/M220P-Python-MongoDB-Course/mflix-python$ python run.py
Traceback (most recent call last):
File “run.py”, line 1, in
from mflix.factory import create_app
File “/mnt/d/Downloads/Personal/Mongo-Certs/M220P-Python-MongoDB-Course/mflix-python/mflix/factory.py”, line 12, in
from mflix.api.movies import movies_api_v1
File “/mnt/d/Downloads/Personal/Mongo-Certs/M220P-Python-MongoDB-Course/mflix-python/mflix/api/movies.py”, line 233
**user_info
^
SyntaxError: invalid syntax

What is the python version you are using?

Kanika

Hi Kanika

(mflix) niraj@ALIPLR2070:/mnt/d/Downloads/Personal/Mongo-Certs/M220P-Python-MongoDB-Course/mflix-python$ python --version

Python 2.7.15 :: Anaconda, Inc.

as this is under Anaconda.

Try implementing on Python 3.7 as suggested by @Kanika

Remove your existing environment (optional)
conda env remove -n <YOUR_ENV_NAME>
conda env remove -n mflix => In your case

Create a new virtual environment with python 3.7
conda create -n <ENVIRONMENT_NAME> python=3.7
conda create -n mflix python=3.7 => In your case

Note that <ENVIRONMENT_NAME> should not already exist in your list of conda environments

1 Like

Thanks, the resolution worked for me. I can run the application and can see the result.

1 Like