Python ConfigParser.NoSectionError:MySQLdb连接时没有部分

时间:2017-07-14 11:09:55

标签: python mysql python-3.x mysql-python

conn_file.cfg:

[user]
connectString=host="192.xx.xx.xx",user="user",passwd="pw",db="college"

db_parser.py

import ConfigParser as cp
import MySQLdb as ms

config = cp.ConfigParser()
config.read(r".\conn_file.cfg")
connectString = config.get('user','connectString')
con = ms.connect(connectString)
print(con)

错误:

Traceback (most recent call last):
  File "db_parser.py", line 6, in <module>
    connectString = config.get('user','connectString')
  File "/usr/lib64/python2.7/ConfigParser.py", line 607, in get
    raise NoSectionError(section)
ConfigParser.NoSectionError: No section: 'user'

0 个答案:

没有答案