Cannot get past this string related issue

O

Oltmans

Greetings, I hope you're doing well. I'm stuck in a strange issue,
most likely due to my own ignorance. I'm reading a config file using
ConfigParser module and passing database related info to _mssql.
Following doesn't work


config = ConfigParser.ConfigParser()
config.read('configs.txt')
server_info = config.get("DB_INFO","server")
db = config.get("DB_INFO","database")
username = config.get("DB_INFO","user")
pwd = config.get("DB_INFO","password")
print server_info,db,username,pwd
conn =
_mssql.connect(server=server_info,database=db,user=username,password=pwd)

but following does work

conn =
_mssql.connect(server='server',database='database',user='user',password='password')


Config file looks like following

[DB_INFO]
server = "server"
database = "database"
user = "user"
password = "password"


But I cannot figure out why? Any ideas or help will be highly
appreciated. Thanks!
 
T

Tim Golden

Greetings, I hope you're doing well. I'm stuck in a strange issue,
most likely due to my own ignorance. I'm reading a config file using
ConfigParser module and passing database related info to _mssql.

[ ... ]
Config file looks like following

[DB_INFO]
server = "server"
database = "database"
user = "user"
password = "password"


A config file isn't a Python file: you don't need (and
don't want) double-quotes around those values.

TJG
 
T

Thomas Rachel

Am 26.04.2011 15:48, schrieb Oltmans:
Following doesn't work


config = ConfigParser.ConfigParser()
config.read('configs.txt')
server_info = config.get("DB_INFO","server")
db = config.get("DB_INFO","database")
username = config.get("DB_INFO","user")
pwd = config.get("DB_INFO","password")
print server_info,db,username,pwd
conn =
_mssql.connect(server=server_info,database=db,user=username,password=pwd)

but following does work

conn =
_mssql.connect(server='server',database='database',user='user',password='password')

Ok, if you are this far: what prevents you from trying

print server_info, db, username, pwd

and being aware that IF there are " around, they are not part of the
string representation, but they are really there.

Config file looks like following

[DB_INFO]
server = "server"
database = "database"
user = "user"
password = "password"

I think if you will have seen the output above, you will probably see
what is wrong here: too many "s. :)

HTH & HAND!

Thomas
 
O

Oltmans

Am 26.04.2011 15:48, schrieb Oltmans:








Following doesn't work
config = ConfigParser.ConfigParser()
config.read('configs.txt')
server_info = config.get("DB_INFO","server")
db = config.get("DB_INFO","database")
username = config.get("DB_INFO","user")
pwd = config.get("DB_INFO","password")
print server_info,db,username,pwd
conn =
_mssql.connect(server=server_info,database=db,user=username,password=pwd)
but following does work
conn =
_mssql.connect(server='server',database='database',user='user',password='pa ssword')

Ok, if you are this far: what prevents you from trying

print server_info, db, username, pwd

and being aware that IF there are " around, they are not part of the
string representation, but they are really there.
Config file looks like following
[DB_INFO]
server = "server"
database = "database"
user = "user"
password = "password"

I think if you will have seen the output above, you will probably see
what is wrong here: too many "s. :)

Many thanks, really appreciate help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top