keyError 'Prod' starting the MFlix

Did you set your .ini file per the instructions? That is where the key “PROD” Key is. You can ignore the secret key, as it has no bearing on the assignments.

I spent about two hours on this myself, I’m assuming it has to do with how you name/setup your cluster.

I had to remove the /test from the end of the URI string. Once I did that I was able to run the tests and get the information to complete the assignments.

SECRET_KEY = secret key goes here
MFLIX_DB_URI = mongodb+srv://

SECRET_KEY = secret key goes here
MFLIX_DB_URI = mongodb+srv://

i got this fixed with the above help, thank you

should at the end of connection it should be \mflix or \test or nothing, got confused after this post


I think that is where the instructions are confusing. By putting < YOUR_CLUSTER_URI>, and saying copy/paste from the Atlas strings the instructions are ambiguous…which may be the goal of the exercise.

I tried several variants.

This is the connection listed in the file

   def get_db():
       db = g._database = MongoClient(
       return db

So reading the code with your URI above should say:

  1. Make a pymongo connection to MFLIX_DB_URI

  2. Use the [“mflix”] db and return the db connection

    return db

To make the above code work I think your URI should say

  1. Using m220student/m220password

  2. Connect to cluster “mflix” using


So from all that, I assumed I should be using and it works for me:

    MFLIX_DB_URI = mongodb+srv://m220student:m220password@mflix-<detailsgohere>

However, like I said in the first post. I’m assuming all of this is dependent on how you set and/or name your project within Atlas.

Hopefully that helps explain my thought process, and helps you get it setup and running.

Does YOUR_CLUSTER_URI contain dbname? Anyways for me it fails with the dbname added, I also added the cluster URI to the db connection test file.

I’ve tried a lot and the error does not stop appearing, do you have any idea what it might be?

(mflix) C:\Users\Ronaldo\MongoDB\University_MongoDB\M220P\mflix-python>python
Traceback (most recent call last):
File “”, line 13, in
app.config[‘MFLIX_DB_URI’] = config[‘PROD’][‘MFLIX_DB_URI’]
File “C:\ProgramData\Anaconda3\lib\”, line 958, in getitem
raise KeyError(key)
KeyError: ‘PROD’


I use Windows 10
I use Anaconda 4.6.14
I use Python 3.7.3

I executed the command below
pip install -r requirements. txt

My dotini.ini file has already been changed according to previous question posts

SECRET_KEY = super_secret_key_you_should_change
MFLIX_DB_URI= mongodb+srv://

SECRET_KEY = super_secret_testing_key
MFLIX_DB_URI= mongodb+srv://

I have already gone through all the parter and I have already validated all the configuration parts again and still the error does not stop showing.
I already installed Flask again and nothing works, it displays the same error.

Hi @Ronaldo_96709,

Please try after changing your filename to “.ini”.

The file path should be “C:\Users\Ronaldo\MongoDB\University_MongoDB\M220P\mflix-python\.ini”.

C:\Users\Ronaldo\MongoDB\University_MongoDB\M220P\mflix-python> ren dotini_win .ini 

Let me know if it works.



I am facing a similar issue on my Mac.

ren command is not working.

When trying to manually rename the “dotini_win” and “dotini_unix” text files to “.ini”. Getting the following error.

You can’t use a name that begins with a dot “.”, because these names are reserved for the system. Please choose another name.

Another question is do we need to modify the secret keys as well in the files?

Please advise what needs to be done.

Thanks in advance,
Ikagarjot Singh

On a MAC I think you should use mv rather than ren.


It worked. Thanks @steevej-1495 :smiley:

I am getting the same errors. None of the proposed fixes above are working for me.

(base) C:\Users\Behemoth>python D:\Projects\Classes\MongoDB\M220\mflix-python\
Traceback (most recent call last):
File “D:\Projects\Classes\MongoDB\M220\mflix-python\”, line 14, in
app.config[‘MFLIX_NS’] = config[‘PROD’][‘MFLIX_NS’]
File “D:\Apps\Anaconda2019.03\lib\”, line 958, in getitem
raise KeyError(key)
KeyError: ‘PROD’

HI @Quawan_25966,

Please try running the command from mflix-python directory where you have created .ini file as well.


Thanks the fix was for me to uninstall anaconda and pycharm and reinstall. Likely a config setting was off from a past project.

1 Like