Error "No section: 'default'" when using Database Library for Robot Framework

2,536 views
Skip to first unread message

James Do

unread,
Aug 1, 2014, 12:01:48 AM8/1/14
to robotframe...@googlegroups.com
Dear,
I am trying to test some database queries with Robot Framework, but I can't connect to database.
I run database MySQL in localhost using XAMPP.
This is my keywords in RIDE:
*** Settings ***
Library           DatabaseLibrary

*** Variables ***
@{DB}             robotframework    root    \    localhost    3306

*** Test Cases ***
Select from database
    [Tags]    This
    Connect To Database    MySQLdb    @{DB}[0]    @{DB}[1]    @{DB}[2]    @{DB}[3]    @{DB}[4]
    @{results}=    Query    Select * from tbName
    Log Many    @{results}

I have installed MySQL db lib for Python to get Mysql driver. 
However, Everytime I run this case, it always return error:
Select from database                                                                             | FAIL |
NoSectionError: No section: 'default'

Please help me to get out of this error. 
Thanks

James Do

unread,
Aug 1, 2014, 6:47:09 AM8/1/14
to robotframe...@googlegroups.com
Nobody knows about it? :(

Kevin O.

unread,
Aug 1, 2014, 9:52:04 AM8/1/14
to robotframe...@googlegroups.com
You have empty string for item with index 2 (@{DB}[2]), corresponding to dbPassword. I'm assuming this means you have a blank password for user root.
This is causing the database library to try and load the value for dbPassword from a config file that does not exist.
This is happening because of this logic:
dbUsername = dbUsername or config.get('default', 'dbUsername')
Here dbUserName is an empty string so it evaluates to False and so the config.get part is used.

Using a user with a password with workaround this issue. Also using a dbConfig file to store the parameters would also workaround the issue. I can think of other workarounds, but the would be more difficult.

Reporting this would be helpful, as I think this is a perfectly valid use case (empty password).

For best practices, I recommend using ${EMPTY} as it is a little more explicit...
@{DB}             robotframework    root    ${EMPTY}    localhost    3306

Also it is more helpful in the future that if you have a problem like this use --loglevel DEBUG. Then you get output that is more helpful like this:
20140801 08:46:16.420 : DEBUG : 
Traceback (most recent call last):
  File "C:\apps\Python27\lib\site-packages\DatabaseLibrary\connection_manager.py", line 67, in connect_to_database
    dbPassword = dbPassword or config.get('default', 'dbPassword')
  File "C:\apps\Python27\lib\ConfigParser.py", line 607, in get
    raise NoSectionError(section)

Cheers,
Kevin

Kevin O.

unread,
Aug 1, 2014, 11:22:54 AM8/1/14
to robotframe...@googlegroups.com
Here's another workaround you might consider (tested it). Totally a hack :)

Add Variables file declaration:
Variables         c:/vars.py

contents of c:/vars.py:
***********************
class AlwaysTrueEmptyUnicode(unicode):
    def __nonzero__(self):
        return True

EMPTY_BUT_TRUE = AlwaysTrueEmptyUnicode()
del AlwaysTrueEmptyUnicode
*************************

Change parameters to:
@{DB}             robotframework    root    ${EMPTY_BUT_TRUE}    localhost    3306

Kevin O.

unread,
Aug 1, 2014, 6:37:01 PM8/1/14
to robotframe...@googlegroups.com
Sorry to reply so much, but I was laser-focused on getting that keyword to work. Instead you should use the more flexible connect keyword:
    Connect To Database Using Custom Params    MySQLdb    db='robotframework',user='root',host='localhost',port=3306
Here, passwd parameter is omitted and a blank password is used.

See http://mysql-python.sourceforge.net/MySQLdb.html#functions-and-attributes for info on the parameters available for MySQLdb.
Reply all
Reply to author
Forward
0 new messages