Reputation: 285
I am using a Ubuntu18 EC2 instance with AWS. I have installed Anaconda package.
When I am directly inside the appropriate directory and run python code.py
it runs fine. However, it does not run when I try to run the script with a file path.
Works
$ python AverageAmountofSessions.py
Not Working:
$ python mycompany/AverageSessions/AverageAmountofSessions.py
Error:
Traceback (most recent call last):
File "mycompany/AverageSessions/AverageAmountofSessions.py", line 126, in <module>
lambda_handler('event','content')
File "mycompany/AverageSessions/AverageAmountofSessions.py", line 28, in lambda_handler
db_host = db_config['mysql']['host']
File "/home/ubuntu/anaconda3/lib/python3.7/configparser.py", line 958, in getitem
raise KeyError(key)
KeyError: 'mysql'
Addition Notes:
Upvotes: 0
Views: 1068
Reputation: 291
Look like it does not find the key mysql wich should be in your ini file. Maybe the path to find your ini file in your scipt is not the good one
i mean if you open you ini file like that :
config = configparser.ConfigParser()
config.read('example.ini')
then the example.ini is not relative fro mwhere you python scipr is but from the $PWD which mean where you are in your shell when you run it !!
if you do something like that and the example.ini is in the same directory as you ini file
import os
config = configparser.ConfigParser()
conffile = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'example.ini')
config.read(conffile)
Upvotes: 1
Reputation: 1166
Are your ini files in the same directory as the python file. It certainly looks like it cant find the file. Id start by checking how your db_config dict is set. If that is the problem,a way around this would be to set the PYTHONPATH variable to the root folder of your source code
Upvotes: 0