[wxPython] Connecting to MySQL

I am unable to connect to MySQL with the following code:

        connect_cmd = 'host="'+self.box_1.GetValue()+'", '\
                      'user="'+self.box_3.GetValue()+'", '\
                      'passwd="'+self.box_4.GetValue()+'", '\
                      'db="'+self.box_2.GetValue()+'"'
        print connect_cmd
        try:
            conn = MySQLdb.connect(connect_cmd)
I get the following error:

Connecting
host="localhost", user="root", passwd="", db="test"

Error 2005: Unknown MySQL Server Host 'host="localhost", user="root",
passwd="", db="test"' (11001)

If I hard code the following, I can connect:

           conn=MySQLdb.connect(host="localhost",
                                 user="root",
                                 passwd="",
                                 db="test")

Ayy suggestions will be appreciated.

···

__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com

[DJ Webre]

I am unable to connect to MySQL with the following code:

        connect_cmd = 'host="'+self.box_1.GetValue()+'", '\
                      'user="'+self.box_3.GetValue()+'", '\
                      'passwd="'+self.box_4.GetValue()+'", '\
                      'db="'+self.box_2.GetValue()+'"'
        print connect_cmd
        try:
            conn = MySQLdb.connect(connect_cmd)
I get the following error:

Connecting
host="localhost", user="root", passwd="", db="test"

Error 2005: Unknown MySQL Server Host 'host="localhost", user="root",
passwd="", db="test"' (11001)

As expected. If you provide a single argument to connect() is assumes that's
the host. So you've given it a host whose name contains (amont other things)
four equals signs. Not surprisingly, it ccan't resolve this into a network
address :slight_smile:

If I hard code the following, I can connect:

           conn=MySQLdb.connect(host="localhost",
                                 user="root",
                                 passwd="",
                                 db="test")

Ayy suggestions will be appreciated.

How about

    conn = MySQLdb.connect(
                    host=self.box_1.GetValue(),
                    user=self.box_2.GetValue(),
                    passwd=self.box_3.GetValue(),
                    db=self.box_4.GetValue())

You can't replace the connect() arguments with a single string (though you
*can* provide defaults in a my.ini file and then tell connect() to use that
file, but I forget the name of the argument that does that).

regards

···

-----------------------------------------------------------------------
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------