Since one of the last Windows 10 updates a Python script has stopped parsing the ini file. Everything worked fine until I updated the quality control computer from Windows 7 last week. Now as I am analysing the problem it does not even work on the same computer on which the code was developed (last edit was Jan 21st). The ini file is located in the same directory like my Python script. I wrote this little code snippet to reproduce the error:
Test-Code:
from pathlib import Path
from configparser import ConfigParser
import os
SETTINGSFILE = r'settings.ini'
p=os.path.dirname(os.path.realpath(__file__))
thispath=Path(p)
p=thispath/SETTINGSFILE
ini=ConfigParser()
ini.read(p)
INI File:
# -*- coding: utf-8 -*-
# comments
#
[GENERAL]
# Default-Wert für den Debugmodus, kann durch Kommandozeilenparameter überschrieben werden
debugmode=False
# falls das Senden erfolgreich war, beendet sich das Programm danach automatisch
autoquit=False
# Passwort für Sonderfreigaben (ohne Anführungsstriche)
password=passwort
# Dateiendungen, die per Default gesendet werden sollen (Komma-getrennt, ohne Leerzeichen)
file_extensions=png,csv
[SERVER]
# IP Adresse für den Upload der Messergebnisse (ohne Anführungsstriche)
# zum Test kann folgende URL verwendet werden
wawi_server = 'http://httpbin.org/post
# soll die Server Adresse im Programm angezeigt werden?
show_server=False
Error:
MissingSectionHeaderError: File contains no section headers.
file: WindowsPath('C:/Users/Stefan Mayrhofer/Documents/Python/wawi-uploader/settings.ini'), line: 1
'# -*- coding: utf-8 -*-\n'
The last line of the error message looks like something is wrong with the coding of the ini file. What can I do to fix this?