首页 > 解决方案 > 如何摆脱 ConfigParser 未定义错误?

问题描述

下面是我的 settings.py 文件。

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)

当我运行命令时,python manage.py celeryd我不断收到以下错误,有人能指出这里出了什么问题吗?

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

标签: pythonpython-3.xceleryconfigparser

解决方案


请在下面进行更改以使代码正常工作。

改变

config = ConfigParser.ConfigParser()

config = configparser.ConfigParser()

然后改变

ctx = ConfigParser.RawConfigParser()

ctx = configparser.RawConfigParser()

推荐阅读