Search code examples
pythonpython-3.xceleryconfigparser

How to get rid of ConfigParser is not defined error?


Below is my settings.py file.

import configparser
import os
import sys

import djcelery
import redis
import raven

djcelery.setup_loader()

# this should disable some of the warnings sam
# import urllib3
# urllib3.disable_warnings()

#####################################################

# this has been moved to config/tools.conf


#####################################################
PROJECT_PATH = os.path.split(os.path.abspath(os.path.join(__file__, os.pardir)))[0]
config = ConfigParser.ConfigParser()

ctx = ConfigParser.RawConfigParser()
ctx.read('%s/config/tools.conf' % PROJECT_PATH)

When I run the command python manage.py celeryd I keep on getting the below error can any one suggest what is going wrong here?

File "/opt/tools/core/settings.py", line 22, in <module>
    config = ConfigParser.ConfigParser()
NameError: name 'ConfigParser' is not defined

Solution

  • Please below changes for the code to work properly.

    change

    config = ConfigParser.ConfigParser()

    to

    config = configparser.ConfigParser()

    And then change

    ctx = ConfigParser.RawConfigParser()
    

    to

    ctx = configparser.RawConfigParser()