I have a script that uses the ConfigParser module to grab settings from a config.ini file. The script runs fine on my local machine, and it runs fine on PythonAnywhere if I run it manually. It's only giving me errors when I run the script through the scheduled tasks interface.
I can get the error with this script:
import configparser
config = configparser.ConfigParser()
config.read("config.ini")
def main():
interval = config.get("scriptsettings", "check_interval")
if __name__ == '__main__':
main()
The scheduled task log looks like this:
Traceback (most recent call last):
File "/usr/lib/python3.6/configparser.py", line 1135, in _unify_values
sectiondict = self._sections[section]
KeyError: 'scriptsettings'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/unchow/project/schedule_test.py", line 11, in <module>
main()
File "/home/unchow/project/schedule_test.py", line 8, in main
interval = int(config.get("scriptsettings", "check_interval"))
File "/usr/lib/python3.6/configparser.py", line 778, in get
d = self._unify_values(section, vars)
File "/usr/lib/python3.6/configparser.py", line 1138, in _unify_values
raise NoSectionError(section)
configparser.NoSectionError: No section: 'scriptsettings'
2018-08-21 16:30:59 -- Completed task, took 28.00 seconds, return code was 1.
If I run a script without the config.get line as a scheduled task, everything works fine. if I run this script from a Python Anywhere bash console, it also works fine. Im running python3.6, both in the bash console and the scheduled tasks.
The test script is also in the same directory as the config.ini file, and all of my other main scripts, so I know it's not a directory issue. From what I can tell, the script is finding the file, just not the relevant section within the file. I've also tested this with multiple different sections within the config file. Im also only using the standard library for this project, so I'm not using a virtualenv or anything like that.
What would cause configparser in particular to act differently when the script is run as a scheduled task? As far as I can tell, that's the only thing that's breaking for me right now.