python - Issue Importing ConfigParser Read File -
intro: have .ini file (a) stores specific credentials. there multiple scripts (b) - of python, php, etc - parse .ini file (a) variables , in same directory .ini file (a). other scripts (c) under directory (not subdirectory) .ini file (a) , parsing scripts (b) not reside import/include these parsing scripts (b) take advantage of parsed, credential variables.
however, i'm getting error "configparser.nosectionerror" when trying run python script (c) using "sudo python <_(c)_>.py". running "sudo python"/interactive python, , importing python parsing script (b) while in directory of .ini file (a) , (b), i'm able access parsed, credential variables.
question: doing wrong? believe permission issue.
folder tree: folder_0 ->sub_folder_0 ->(a) ->(b) ->sub_folder_1 ->(c)
(a)
[host] ip = 111.111.1.222 [schema] name = derp_a_der [user] name = root password = sexysback
(b)
import configparser cp; config = cp.configparser(); config.read("b.ini"); m_p = config.get("user", "password"); m_h = config.get("host", "ip"); m_n = config.get("schema", "name"); m_u = config.get("user", "name");
(c)
import sys; import os; mysql_config_path = "/folder_0/sub_folder_0/"; sys.path.append( os.path.abspath(mysql_config_path) ); import mysqlconfig myc; print myc.m_u;
when config file not found, empty dataset used, exception nosectionerror should alter directory config file located before running script
os.chdir(mysql_config_path)
or utilize total path in target script (in config.read())
python linux
No comments:
Post a Comment