![]() |
configparser.NoSectionError (Python 3.7) - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: configparser.NoSectionError (Python 3.7) (/thread-25101.html) |
configparser.NoSectionError (Python 3.7) - alpho - Mar-19-2020 Hello. When my script is restarting I often times will have these configuration errors. Importing: import configparserAbsolute file path (attempt to fix this, didn't help): thisfolder = os.path.dirname(os.path.abspath(__file__)) test_config_path = os.path.join(thisfolder, '/home/pi/test_configuration.ini') assert os.path.exists(test_config_path)Load from that absolute path: Config = configparser.ConfigParser() Config.read(test_config_path)My Read / Write functions: # Read the Configuration File def readConfig(section, key): Config = loadConfiguration() return Config.get(section, key) # Write to the Configuration File def writeConfig(section, key, value): Config = loadConfiguration() Config.set(section, key, str(value)) with open(raindeck_config_path, "w") as configfile: Config.write(configfile) return ConfigThe error I'm receiving Exception in thread Thread-5: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self._kwargs) File "/home/pi/test_minion.py", line 821, in begin runSequence(zone_id) File "/home/pi/test_minion.py", line 418, in runSequence outputMIDI("Water", program_water_name, zone_id) File "/home/pi/test_minion.py", line 295, in outputMIDI solenoids_zone_2 = int(readConfig("Program", "program_total_solenoids_zone_2")) File "/home/pi/test_minion.py", line 189, in readConfig Config = loadConfiguration() File "/home/pi/test_minion.py", line 129, in loadConfiguration Config_ServerName = Config.get("Server", "Server_Name") File "/usr/lib/python3.7/configparser.py", line 780, in get d = self._unify_values(section, vars) File "/usr/lib/python3.7/configparser.py", line 1146, in _unify_values raise NoSectionError(section) from None configparser.NoSectionError: No section: 'Server'I am using threads throughout this script and the script is killed and restarted at the end. Thank you RE: configparser.NoSectionError (Python 3.7) - alpho - Mar-19-2020 I have searched all over google, tried everything I've found with no success. It seems like the configparser does not like threads. I have to use threads for this project however. Any recommendations? RE: configparser.NoSectionError (Python 3.7) - micseydel - Apr-08-2020 Sounds like a problem in the .ini file you didn't provide. |