0

I'm getting configparser.NoSectionError: No section: 'creds

Config.cfg file

[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')

Error

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'

Anybody know what could be the issue ?

itsAPK
  • 103
  • 1
  • 10
  • 1
    Are you sure you're actually reading the file? Try printing the entire config object before you looking up a particular session. – 9000 Apr 06 '20 at 05:44
  • File is `Config.cfg` but you read from `config.cfg`, maybe that's the problem – fas Apr 06 '20 at 05:44
  • @user3365922 (s)he is on windows, nobody cares about the upper/lower case – lenik Apr 06 '20 at 05:46
  • It's returning "NoSectionError ", It is not related to filename.I checked @user3365922 – itsAPK Apr 06 '20 at 05:49
  • Does this answer your question? [Python ConfigParser.NoSectionError: No section:](https://stackoverflow.com/questions/35016479/python-configparser-nosectionerror-no-section) – zypro Apr 06 '20 at 06:18
  • Possible duplicate: https://stackoverflow.com/questions/35016479/python-configparser-nosectionerror-no-section/35017127 – zypro Apr 06 '20 at 06:19

0 Answers0