ini文件内容:
[base]
browser_type=Chrome
borwser_url=http://112.116.107.117:8080/jenkins/job/ota%E5%8D%87%E7%BA%A7/
file_name=config.ini
读取ini文件函数如下:
def getConfig(self,section, key, settings_file):
self.config = ConfigParser()
self.path = os.path.join(os.path.split(os.path.realpath(__file__))[0],settings_file)
#print('ini文件路径:',self.path)
self.config.read(self.path)
return self.config.get(section, key)
执行后报错:
原因:url: http://112.116.107.117:8080/jenkins/job/ota%E5%8D%87%E7%BA%A7/ 包含特殊符号%
解决方法:conf=Configparser() 改为 conf=RawConfigparser()
修改后的代码:
def getConfig(self,section, key, settings_file):
self.config = RawConfigParser()
self.path = os.path.join(os.path.split(os.path.realpath(__file__))[0],settings_file)
#print('ini文件路径:',self.path)
self.config.read(self.path)
return self.config.get(section, key)
修改后执行OK
标签:os,self,报错,ini,file,path,config,configparser From: https://www.cnblogs.com/yimobaihe/p/16731935.html