python - 如何摆脱 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
解决方案
请在下面进行更改以使代码正常工作。
改变
config = ConfigParser.ConfigParser()
到
config = configparser.ConfigParser()
然后改变
ctx = ConfigParser.RawConfigParser()
到
ctx = configparser.RawConfigParser()
推荐阅读
- node.js - NodeJS 连接到 SQL Server getaddrinfo ENOTFOUNT
- maven - 如何使用应用安装令牌向 GitHub Package Registry 进行身份验证?
- mysql - MYSQL 错误消息 - 将 INTERVAL 更改为 24hrs(从 23hrs)导致错误 1242。子查询返回超过 1 行
- typescript - 反应原生打字稿呈现文本onPress
- next.js - 元标记未显示在 Next.js 的查看源代码中
- typescript - 为什么 TypeScript 不报告“错误”的函数返回类型
- android - 启动应用程序时出现 React Native 未知错误
- python - 根据列标题获取Excel列字母 - Python
- angular - 如何以角度将富文本显示为工具提示
- bash - ffmpeg:来自图像的视频 - 处理零长度的图像文件