configparser封装后报错:configparser.NoSectionError: No section: 'LoginElement'
前言
这是目录结构

先贴一下源代码
# read_ini.py
import configparser class ReadIni():
"""读取 ini.ini 配置文件"""
def __init__(self, file_name=None, note=None):
if file_name == None:
file_name = '../config/ini.ini'
if note == None:
self.note = 'LoginElement'
else:
self.note = note
self.cf = self.load_file(file_name) # 加载文件
def load_file(self, file_name):
cf = configparser.ConfigParser()
cf.read(file_name)
return cf # 获取key
def get_value(self, key):
return self.cf.get(self.note, key)
# ini.ini [LoginElement]
username=name>username
userpassword=name>password
usersubmit=xpath>//*[@id="login-form"]/div[3]/input
在 Python 控制台 运行的代码
from util.read_ini import ReadIni a = ReadIni()
a.get_value('username')
然后我们会神奇的发现 报了一个错误: configparser.NoSectionError: No section: 'LoginElement'
分析
可以看见报错的信息是没有找到 LoginElement 这个节点,可是ini.ini 这个文件中是有这个节点,为啥找不到了???

然后决定先从第一步开始分析:这个文件有没有加载到(很多时候都是因为文件路径产生的问题)
现在写的是相对路径,先改成绝对路径试下。。。。。
改完路径后你就会发现,你的问题已经解决了
总结
这个问题的原因是因为配置文件没有加载到,在加载文件的时候尽可能的使用 绝对路径,记得格式化文件路径,防止文件路径错误
configparser封装后报错:configparser.NoSectionError: No section: 'LoginElement'的更多相关文章
- python 读取配置文件总是报错 configparser.NoSectionError: No section:
本文为作者原创,禁止转载,违者必究法律责任!!! python 读取配置文件总是报错 configparser.NoSectionError: No section: 无论是 python2的版本,还 ...
- zabbix安装unixODBC配置完之后报错
zabbix安装unixODBC配置完之后报错 libmysqlclient_16 not defined in file libmysqlclient_r.so.16 分析 我没有使用centos6 ...
- 我用VS2012在Nuget中安装Signalr之后报错
我用VS2012在Nuget中安装Signalr之后报错 “/”应用程序中的服务器错误. The following errors occurred while attempting to load ...
- 服务器的SVN项目版本较低,check out 下来后报错
check out下来后报错提示: svn: E155036: Please see the 'svn upgrade' commandsvn: E155036: Working copy '/hom ...
- 项目导入之后报错:The import javax.servlet cannot be resolved
项目导入之后报错:The import javax.servlet cannot be resolved 解决方法:在Eclipse中,右击项目,选择Build Path->configure ...
- Android 加了自定义Application后报错 Unable to instantiate activity ComponentInfo ClassNotFoundException
在Android自定义一个类继承集成Application后,并在AndroidManifest.xml里面配置了application的name属性为该类名称后报错: Unable to insta ...
- maven项目检出后报错(包括编译报错和运行报错)的常见检查处理方式
maven项目检出后报错(包括编译报错和运行报错)的常见检查处理方式: 1.更改项目的jdk为我们安装的jdk2.更改build配置里的 output folder 目录为 xxx项目名/target ...
- 解决mac安装homebrew后报错-bash: brew: command not found
解决mac安装homebrew后报错-bash: brew: command not found 参照官网上很简单的一句安装命令, /usr/bin/ruby -e "$(curl ...
- 【Devops】【docker】【CI/CD】jenkins源码管理,添加SSH地址后报错+Jenkins构建报错:Please make sure you have the correct access rights and the repository exists.
jenkins源码管理,添加SSH地址后报错: Could not read from remote repository. Please make sure you have the correct ...
- git添加公钥后报错sign_and_send_pubkey: signing failed: agent refused operation
在服务器添加完公钥后报错 sign_and_send_pubkey: signing failed: agent refused operation 解决方案: eval "$(ssh-ag ...
随机推荐
- Nebula Operator 云上实践
本文首发于 Nebula Graph Community 公众号 嗨,大家好!Nebula Operator 开源也有一段时间了,之前也有一篇相关的博客介绍,但是实践相关的博客却还没有,现在: 它来了 ...
- TCP的链接和断开_wireShark实践
目录 准备 TCP连接的三次握手 WireShark验证 TCP的四次挥手 WireShark验证 状态解释 其他的 # 概述 终于到了学习总结时间了 准备 TCP连接的三次握手 转自https:/ ...
- VC-MFC 登陆界面 + 数据库账号+密码
1 // DlgUser.cpp : 实现文件 2 // 3 4 #include "stdafx.h" 5 #include "Login.h" 6 #inc ...
- SQL之 逻辑库,数据表
SQL语言三大类 创建逻辑库 创建数据表 例子 数据表其他操作 ps:desc仅仅查看表的结构,不能查看内容 添加字段 ps: 修改字段类型和约束 修改字段名称 删除字段
- 单词本z escort 护卫 es=ex 出去 cor=con=com 一起, 一起出去 = 护卫
单词本z escort 护卫 es=ex 出去 cor=con=com 一起, 一起出去 = 护卫 escort 护卫, 护送 这个单词按照我自己理解的反而好记住 es = ex = 出 cor = ...
- mybatis-plus详细使用教程
mybatis-plus使用教程 欢迎关注博主公众号「Java大师」, 专注于分享Java领域干货文章http://www.javaman.cn/jszw/mybatis-plus 什么是Mybati ...
- ETL工具-KETTLE教程实例实战3----转换(输入、输出)
ETL工具-KETTLE教程实例实战3----转换(输入.输出) 欢迎关注笔者的公众号: java大师, 每日推送java.kettle运维等领域干货文章,关注即免费无套路附送 100G 海量学习.面 ...
- Window10系统通过软件切换扬声器与耳机的音源输出
原文地址: Window10系统通过软件切换扬声器与耳机的音源输出 - Stars-One的杂货小窝 个人平常一般使用扬声器,但有时候直播或和别人打游戏的时候,可能会带上耳机 目前的情况就是手动去插播 ...
- 网络流媒体协议的联系与区别 (RTP RTCP RTSP RTMP HLS)(转)
网络流媒体协议的联系与区别(RTP RTCP RTSP RTMP HLS) RTP RTCP RTSP RTMP HLS 区别与联系 RTP传输流媒体数据.RTCP对RTP进行控制,同步.RTSP发起 ...
- NVIDIA Jestson TX2 配置cuda以及cudnn的坑 ( JetPack-L4T 、Error: downloading update lock、TX2,TX1,TK1相关资源信息)
PS:要转载请注明出处,本人版权所有. PS: 这个只是基于<我自己>的理解, 如果和你的原则及想法相冲突,请谅解,勿喷. 前置说明 本文作为本人csdn blog的主站的备份.(Bl ...