Closed DerfOh closed 8 years ago
it needs code like this instead
Config.read(path.dirname(path.realpath(__file__)) + '/alarm.config')
BUT, this path should really be a variable so you can pass the path to a configuration file outside of the git repository
can you elaborate? how to make this work outside of install directory?
Here's how I fixed this:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
os.chdir(os.path.dirname(sys.argv[0])) # When called from cron, we can find our code
import ConfigParser
...
Thanks! I put this project up on a shelf a long time ago, I will dust it off and try your fix though! For now I will close this issue though.
Not sure where the issue is but when I try to run the script outside of the alarmpi directory. For example if I run it from the pi user directory I get the following output.
pi@raspberrypi ~ $ python alarmpi/sound_the_alarm.py Traceback (most recent call last): File "alarmpi/sound_the_alarm.py", line 31, in
head = Config.get('main','head')+" "
File "/usr/lib/python2.7/ConfigParser.py", line 607, in get
raise NoSectionError(section)
ConfigParser.NoSectionError: No section: 'main'
Looks like it's having problems with the config file but no errors are thrown when I run it from within the alarmpi directory.As a result I'm also unable to get the cron job to properly run. Any ideas?