keyError 'Prod' starting the MFlix

Trying to start MFlix I receive next error:

C:\MongoDB\M220\mflix-python>python run.py
Traceback (most recent call last):
File “run.py”, line 13, in
app.config[‘MFLIX_DB_URI’] = config[‘PROD’][‘MFLIX_DB_URI’]
File “C:\ProgramData\Anaconda3\lib\configparser.py”, line 959, in getitem
raise KeyError(key)
KeyError: ‘PROD’

Maybe the problem is in dotini.ini file in the SECRET_KEY which I haven’t found

Please help

Hi @alroy,

Can you paste here your .ini file contents?
This looks like you are missing to define the MFLIX_DB_URI in your configuration file (.ini)

N.

Hi, Norberto

here is my .ini file. But its full name is dotini_win.ini is it correct?

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://mflix-iyvs8.mongodb.net/test

[TEST]
SECRET_KEY = super_secret_testing_key
MFLIX_DB_URI = mongodb+srv://mflix-iyvs8.mongodb.net/test

1 Like

Hi @alroy

you need to rename the dotini_win.ini to .ini otherwise the file configuration won’t be picked up.

You can rename the file using your file system browser/explorer or by running this command in your cmd window:

ren dotini_win.ini .ini

N.

2 Likes

Thank you, @Norberto

Now is working

Hi Alroy,

In the .ini file should we specify our login details as well? Like the username/password combo. The instruction is not clear. Thanks.

Hi, @mjshaheed

You just need to change MFLIX_DB_URI sections. Look at my file and this should help

Hi @mjshaheed,

The MongoDB Atlas uri should include the username and password :

mongodb+srv://USERNAME:PASSWORD@server_address.mongodb.net/dbname

In your case, the username and password should be the ones we ask you to create

mongodb+srv://m220student:m220password@server_address.mongodb.net/mflix

In the README lesson you have the instructions to set the connection string correctly:

MongoDB Atlas Cluster

The below example connects to Atlas as the user you created before, with username m220student and
password m220password. You can run this command from your command line:
mongo “mongodb+srv://m220student:m220password<YOUR_CLUSTER_URI>”

In any case, we will make this a bit clearer in the lab instructions.

N.

1 Like

On a Mac OSX 10.14 and saved the Atlas config in the dotini.ini file but when I do python run.py I get the following:

(mflix) JRs-MacBook-Pro:mflix-python sandeepmohan$ python run.py Traceback (most recent call last): File "run.py", line 13, in <module> app.config['MFLIX_DB_URI'] = config['PROD']['MFLIX_DB_URI'] File "/Users/sandeepmohan/anaconda/envs/mflix/lib/python3.6/configparser.py", line 959, in __getitem__ raise KeyError(key) KeyError: 'PROD' (mflix) JRs-MacBook-Pro:mflix-python sandeepmohan$

I saw this thread and even renamed _win.ini and checked the original one as well.

I see this:

`# 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@cluster0-qaoqe.mongodb.net/mflix

[TEST]
SECRET_KEY = super_secret_testing_key
MFLIX_DB_URI = mongodb+srv://m220student:m220password@cluster0-qaoqe.mongodb.net/mflix
`

But I still get the same error at launch.

Any thoughts

Did you rename the dotini_win file to _win.ini ? If so, that is incorrect. It would need to be .ini instead.

so turned out I needed to pip install config parser but now get an error elsewhere:

(mflix) JRs-MacBook-Pro:mflix-python sandeepmohan$ python run.py Traceback (most recent call last): File "run.py", line 1, in <module> from mflix.factory import create_app File "/Users/sandeepmohan/Desktop/Mongo_for_python/m220/mflix-python/mflix/factory.py", line 12, in <module> from mflix.api.movies import movies_api_v1 File "/Users/sandeepmohan/Desktop/Mongo_for_python/m220/mflix-python/mflix/api/movies.py", line 243 **user_info ^ SyntaxError: invalid syntax

Went to /api/movies.py and removed the asterixes but it gives me another syntax error complaining about the }) right after that.

Just getting this up and running is pretty frustrating.

this is the block it seems to have a problem with:

def get_conn_pool_size(): try: (pool_size, w_concern, user_info) = get_configuration() return jsonify({ 'status': 'success', 'pool_size': pool_size, 'wtimeout': w_concern._WriteConcern__document.get('wtimeout', '0'), **user_info }) except Exception as e: return jsonify({'status': 'fail', 'error': str(e)})

Are you using virtualenv properly? The fact that you were missing a key dependancy and you’re seeing syntax errors like that is a sign that your environment is not setup properly. Is your python version showing as python 3 when you run the comand python --version ?

Had launched the env with python 3.6 but conda downgraded to accommodate config parser. When I went back to install 3.6 here is the message I get:

`UnsatisfiableError: The following specifications were found to be in conflict:

  • configparser -> python=2.7
  • python==3.6.6
    Use "conda info " to see the dependencies for each package.`

Ah man, yeah that’s a bit difficult. I don’t have any experience with anything other than Linux and virtualenv so I don’t have much experience to draw on to help. But at least you know that you have to focus on getting your environment right now. I’d recommend going back through the instructions for the envrionment and read very carefully.

Thanks, Austin. Hopefully someone from the training team picks this thread up…

@Norberto - So I have modified my dotini.in to read as follows:

[PROD]
SECRET_KEY = 123456787654321
MFLIX_DB_URI = mongodb+srv://m220student:m220password@cluster0-qaoqe.mongodb.net/mflix?retryWrites=true

[TEST]
SECRET_KEY = 123456787654321
MFLIX_DB_URI = mongodb+srv://m220student:m220password@cluster0-qaoqe.mongodb.net/mflix?retryWrites=true

I have also used the connection string to connect to the cluster using:

mongodb+srv://m220student:m220password@cluster0-qaoqe.mongodb.net/mflix?retryWrites=true

I am logged in and can access dbs and connections.

when I run pytest - m connection , I get 4 errors around KeyError: 'PROD' and KeyError: 'TEST'

Using Anaconda 3, Python 3.7 on Mac OSX 10.14 with all requirements met. If you see further down the this thread, I had a whole bunch of issues around the environment so uninstalled and reinstalled a fresh Anaconda and loaded all packages per requirements as well.

Glad to see that you got your environment setup properly!
Are you executing pytest -m connection from the same directory that your run.py file is at?

Also I think this is more related to a different discussion that was already opened. FYI

yep. Both from the same directory but run.py and pytest -m connection just not working.

Last login: Thu Oct 18 15:24:37 on ttys000 JRs-MacBook-Pro:~ sandeepmohan$ cd Desktop/Mongo_for_python/m220/mflix-python/ JRs-MacBook-Pro:mflix-python sandeepmohan$ python run.py Traceback (most recent call last): File "run.py", line 13, in <module> app.config['MFLIX_DB_URI'] = config['PROD']['MFLIX_DB_URI'] File "/Applications/anaconda3/lib/python3.7/configparser.py", line 958, in __getitem__ raise KeyError(key) KeyError: 'PROD' JRs-MacBook-Pro:mflix-python sandeepmohan$

I think that means that the application cannot find your .ini file.

2 Likes