Python Forum
configparser.NoSectionError (Python 3.7)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
configparser.NoSectionError (Python 3.7)
#1
Question 
Hello. When my script is restarting I often times will have these configuration errors.

Importing:
import configparser
Absolute 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 Config
The 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
Reply
#2
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?
Reply
#3
Sounds like a problem in the .ini file you didn't provide.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ConfigParser(dict_type=) not behaving as expected malonn 5 3,225 Sep-08-2022, 08:42 AM
Last Post: malonn
  using alternate names in configparser Skaperen 6 2,765 Oct-01-2020, 08:27 PM
Last Post: Skaperen
  Error in configparser fullstop 12 9,791 Dec-22-2019, 07:36 PM
Last Post: snippsat
  Help with ConfigParser EricALionsFan 3 3,202 Jul-27-2018, 08:46 PM
Last Post: buran
  ConfigParser.NoSectionError: No section: 'Default' degenaro 1 14,360 Jun-08-2018, 08:33 PM
Last Post: ljmetzger
  No module named 'ConfigParser' Bani 13 55,862 May-22-2017, 08:02 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020