前言

这是目录结构

先贴一下源代码

# 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'的更多相关文章

  1. python 读取配置文件总是报错 configparser.NoSectionError: No section:

    本文为作者原创,禁止转载,违者必究法律责任!!! python 读取配置文件总是报错 configparser.NoSectionError: No section: 无论是 python2的版本,还 ...

  2. zabbix安装unixODBC配置完之后报错

    zabbix安装unixODBC配置完之后报错 libmysqlclient_16 not defined in file libmysqlclient_r.so.16 分析 我没有使用centos6 ...

  3. 我用VS2012在Nuget中安装Signalr之后报错

    我用VS2012在Nuget中安装Signalr之后报错 “/”应用程序中的服务器错误. The following errors occurred while attempting to load ...

  4. 服务器的SVN项目版本较低,check out 下来后报错

    check out下来后报错提示: svn: E155036: Please see the 'svn upgrade' commandsvn: E155036: Working copy '/hom ...

  5. 项目导入之后报错:The import javax.servlet cannot be resolved

    项目导入之后报错:The import javax.servlet cannot be resolved 解决方法:在Eclipse中,右击项目,选择Build Path->configure ...

  6. Android 加了自定义Application后报错 Unable to instantiate activity ComponentInfo ClassNotFoundException

    在Android自定义一个类继承集成Application后,并在AndroidManifest.xml里面配置了application的name属性为该类名称后报错: Unable to insta ...

  7. maven项目检出后报错(包括编译报错和运行报错)的常见检查处理方式

    maven项目检出后报错(包括编译报错和运行报错)的常见检查处理方式: 1.更改项目的jdk为我们安装的jdk2.更改build配置里的 output folder 目录为 xxx项目名/target ...

  8. 解决mac安装homebrew后报错-bash: brew: command not found

    解决mac安装homebrew后报错-bash: brew: command not found     参照官网上很简单的一句安装命令, /usr/bin/ruby -e "$(curl ...

  9. 【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 ...

  10. git添加公钥后报错sign_and_send_pubkey: signing failed: agent refused operation

    在服务器添加完公钥后报错 sign_and_send_pubkey: signing failed: agent refused operation 解决方案: eval "$(ssh-ag ...

随机推荐

  1. Hugo 建站经验之谈

    前言 建站工具,早已不是一个新颖的话题,抛开可视化建站单论开发层面,各类语言都有推出广受欢迎的建站框架,比如 Python 开发的 Pelican,JavaScript 开发的 Hexo,以及市场份额 ...

  2. Java instanceof 全小写 关键字使用

    1 package com.bytezreo.duotai2; 2 3 import java.sql.Date; 4 5 /** 6 * 7 * @Description 面向对象的特征三 ---- ...

  3. apt-get upgrade 和apt-get dist-upgrade区别

    kali  linux系统或者 debian等系统 以及centos  在系统升级后经常会出现系统无法启动,或者启动之后GUI功能没有的问题: 笔记:   区别这两种用法 apt-get update ...

  4. 离线部署-docker

    离线部署---docker 关键词:docker离线部署,images离线安装,docker compose,shell,minio docker离线安装 docker install offline ...

  5. GaussDB(DWS)集群通信:详解pooler连接池

    本文分享自华为云社区<GaussDB(DWS) 集群通信系列一:pooler连接池>,作者:半岛里有个小铁盒. 1.前言 适用版本:[8.1.0(及以上)] GaussDB(DWS) 为M ...

  6. 借助 Terraform 功能协调部署 CI/CD 流水线-Part 2

    在第一部分的文章中,我们介绍了3个步骤,完成了教程的基础配置: 使用 Terraform 创建 AWS EKS Infra 在 EKS 集群上部署 ArgoCD 及其依赖项 设置 Bitbucket ...

  7. electron打包踩过的坑总结 好文

    electron打包踩过的坑总结 https://segmentfault.com/a/1190000018533945

  8. Git | Git Server 搭建,在自己的服务器上进行 git server 搭建

    系列文章目录 目录 系列文章目录 前言 操作 1. 创建 git 用户 2. 创建 .ssh 目录 3. 自定义仓库的根目录 4. 在服务器上创建个裸仓库 5. 手动配置一个公钥 6. 在本地测试一下 ...

  9. 【开源库推荐】#5 Android高亮引导库

    原文:[开源库推荐]#5 Android高亮引导库 - Stars-One的杂货小窝 本文介绍2个高亮引导库HighLightPro和Curtain hyy920109/HighLightPro: A ...

  10. 安装完exe版本jdk之后未配置java_home和path环境变量仍然可以在cmd中使用java命令原因解释

    如题: 为何可以 打出Java -version的版本 ,因为jdk安装过程,拷贝了java\javac等几个命令到C:\windows\system32目录了. 如果使用javac -version ...