python执行报错 configparser.NoSectionError: No section: 'section_1'
场景:请求获取验证码模块regVC.py读取配置文件config.ini时,regVC.py模块单独执行正常,但通过run_all.py模块批量执行时报错,找不到section
解决办法:配置文件路径需写绝对路径
config.ini文件如下:

regVC.py模块代码如下:
import requests
import configparser
import unittest
from Case.readexcel import ExcelData
import json class registerVerifyCode(unittest.TestCase):
def setUp(self):
self.Purl = "/api/register/getVerifyCode"
#取配置文件内数据
self.config = configparser.ConfigParser()
self.text = self.config.read("F:\\Case\\config.ini") #这里要写配置文件的绝对路径
self.section = self.config.sections()
self.option = self.config.options("section_1")
self.item = self.config.items("section_1")
self.url = self.config.items("section_1")[1][1]+self.Purl
self.headers = self.config.items("section_1")[0][1]
#self.headers由str类型转化为字典类型
self.header = eval(self.headers)
self.data_path = self.config.items("section_1")[2][1]
self.sheetname = "注册验证码获取"
self.data = ExcelData(self.data_path,self.sheetname).readExcel()
print(self.url)
print(self.data) def test_reVC(self):
for a in self.data:
for b in a:
print(a)
print(b)
par = {"data":{
b:a[b]
}
}
print(par)
par_json = json.dumps(par)
res = requests.post(self.url,par_json,headers=self.header)
print(res.text)
if "手机号码已注册" in res.text:
print("该手机号码已注册")
if "请求注册验证码成功" in res.text:
print("请求注册验证码成功") if __name__ == '__main__':
unittest.main()
run_all.py代码如下:
import unittest def all_case():
case_dir = "F:\\KEJINSUO_interface\\Case\\"
testCase = unittest.TestSuite()
discover = unittest.defaultTestLoader.discover(case_dir, pattern = "reg*.py", top_level_dir = None)
testCase.addTest(discover)
return testCase if __name__ == '__main__':
runner = unittest.TextTestRunner()
runner.run(all_case())
代码需慢慢优化,先实现简单的功能
python执行报错 configparser.NoSectionError: No section: 'section_1'的更多相关文章
- python 读取配置文件总是报错 configparser.NoSectionError: No section:
本文为作者原创,禁止转载,违者必究法律责任!!! python 读取配置文件总是报错 configparser.NoSectionError: No section: 无论是 python2的版本,还 ...
- 第一次打开pycharm运行python文件报错”No Python interpreter selected“问题的解决办法
前面没有细讲,这里细述一下安装pycharm后,第一次打开pycharm运行python文件报错"No Python interpreter selected"问题的解决办法. 出 ...
- oracle创建包后执行报错:object omgmig.test_package is invalid.
今天学习了一下oracle的包的写法,然后碰到这么个问题.包声明和包主体都正确,但是就是执行报错:object omgmig.test_package is invalid. 这是会报错的sql,看起 ...
- salt执行报错一例
执行报错: 查看服务端日志: 认证有问题 重新认证吧!!! minion端: [root@super66 ~]# cd /etc/salt/[root@super66 salt]# lsminion ...
- Ubuntu下sh *.sh使用==操作符执行报错
----<鸟哥的Linux私房菜--基础篇>学习笔记 ubuntu默认的sh是连接到dash,而我们写shell脚本时使用的时bash.bash和dash在一些方面是不兼容的.因此执行同一 ...
- windows中修改catalina.sh上传到linux执行报错This file is needed to run this program解决
windows中修改catalina.sh上传到linux执行报错This file is needed to run this program解决 一.发现问题 由于tomcat内存溢出,在wind ...
- mac 上python编译报错No module named MySQLdb
mac 上python编译报错No module named MySQLdb You installed python You did brew install mysql You did expor ...
- 调用python脚本报错/usr/bin/env: python : No such file or directory
一.调用python脚本报错 /usr/bin/env: python: No such file or directory 二.解决方法 原因是在windows上编写的脚本,使用dos2unix对脚 ...
- apscheduler 执行报错No handlers could be found for logger "apscheduler.executors.default
执行报错如下: No handlers could be found for logger "apscheduler.executors.default 解决: 加入日志,查看具体报错,载根 ...
随机推荐
- HDU 2273
http://acm.hdu.edu.cn/showproblem.php?pid=2273 N辆车排队过马路,不能相撞,问最短时间 ans=车的总长度/最小速度 #include <iostr ...
- 一名十年Java程序员回忆阿里面试经历——揭开阿里面试的“遮羞布”
阿里面试经历 去阿里面试可以说非常非常的偶然和戏剧性,因为本人根本没投简历,以至于阿里hr给我电话的时候我一度认为是诈骗电话.因为深圳这家公司不错我还想在这里干个两年左右再考虑考虑. 这个时候的本人已 ...
- learn go anonymous function
package main // 参考文档: // https://github.com/Unknwon/the-way-to-go_ZH_CN/blob/master/eBook/06.8.md im ...
- [持续更新]Python 笔记
本文以 Python 2.7 为基础. lambda 函数实现递归 方法一:传递一个 self 参数 求阶乘: frac = lambda self, x: self(self, x - 1) * x ...
- Python学习-购物车程序
程序:购物车程序 需求: 启动程序后,让用户输入工资,然后打印商品列表 允许用户根据商品编号购买商品 用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒 可随时退出,退出时,打印已购买商品和余额 ...
- 《DSP using MATLAB》示例Example 8.11
%% ------------------------------------------------------------------------ %% Output Info about thi ...
- c++重在运算符
运算符函数的定义与其他函数的定义类似,惟一的区别是运算符函数的函数名是由关键字operator和其后要重载的运算符符号构成的.运算符函数定义的一般格式如下: <返回类型说明符> opera ...
- bzoj 3671 [Noi2014]随机数生成器——贪心(时间复杂度分配)
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3671 设 x 为一个点的行号, y 为一个点的列号:原本想着判断一个点能不能选就是看选了的点 ...
- vs2015安装ORACLE的DbFirst
不说DbFirst好在哪里,它和ModelFirst,CodeFirst都各有各的好,由于对于已经存在的一个大型的业务库,使用EntityFramework的更倾向于DbFirst,因为好多同事已经习 ...
- stl map一对多用法
// stlMap.cpp : Defines the entry point for the console application.//#pragma warning (disable : 478 ...