python 使用中遇到的问题,记录及解决方法

1、读取configparser 配置文件报错   :

提示:

 ConfigParser.MissingSectionHeaderError when parsing rsyncd config file with global options

解决方法:

https://stackoverflow.com/questions/22501121/configparser-missingsectionheadererror-when-parsing-rsyncd-config-file-with-glob

cfg = configparser.ConfigParser()
    with open(file,'r') as fp:
        cfg.read_file(itertools.chain(['[global]'], fp), source=file)

    # config.read(file,encoding='utf-8')
    gw_sip = cfg.get('test_sip_endpoint','gw_sip')

posted @ 2019-01-10 18:28  Ray_lei  阅读(331)  评论(0编辑  收藏  举报