configparser.NoSectionError: Нет раздела: 'creds' в Python - PullRequest
0 голосов
/ 06 апреля 2020

Я получаю configparser.NoSectionError: Нет раздела: 'creds

Файл Config.cfg

[creds] 
token = telegram_bot_token

code.py file

class telegram_bot() :
     def __init__(self,config):
         self.token=self.read("config.cfg")
         self.base="https://api.telegram.org/bot{}/".format(self.token)

    def read(self,config):
        self.parser=cfg.RawConfigParser()
        self.parser.read(config)
        return self.parser.get('creds','token')

Ошибка

Traceback (most recent call last):
  File "MAINSERVER.PY", line 5, in <module>
    bots=telegram_bot("config.cfg")
  File "G:\BOT\TBOT\bs4\qrcode\main.py", line 6, in __init__
    self.token=self.read("config.cfg")
  File "G:\BOT\TBOT\bs4\qrcode\main.py", line 24, in read
    return self.parser.get('creds','token')
  File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python38-32\lib\configparser.py", line 781, in get
    d = self._unify_values(section, vars)
  File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python38-32\lib\configparser.py", line 1149, in _unify_values
    raise NoSectionError(section) from None
configparser.NoSectionError: No section: 'creds'

Кто-нибудь знает, в чем может быть проблема?

...