Hello guys I am currently working in a python project at my school. First I 
want to make clear that I'm not a python programmer (I was just called to put 
out the flames in this project because no one else would and I was brave enough 
to say yes).

I have the following problem here. I have to write a method that connects to an 
existing localhost MySQL database (I'm using connector version 1.0.12) and then 
does pretty basic stuff. The parameters are sent by a GTK-written GUI (I didn't 
write that interface). So I wrote my method like this:

--------------------------PYTHON  CODE----------------------------------------
  def compMySQL(self, user, database, password, db_level, table_level, 
column_level):
    sql_page_textview = self.mainTree.get_widget('sql_text_view')
    sql_page_textview.modify_font(pango.FontDescription("courier 10"))
    sql_page_buffer = sql_page_textview.get_buffer()

    #Gonna try connecting to DB
    try:
      print("Calling conn with U:{0} P:{1} 
DB:{2}".format(user,password,database))
      cnxOMC = mysql.connector.connect(user, password,'localhost',database)
    except:
      print "Error: Database connection failed. User name or Database name may 
be wrong"
      return

    #More code ...
------------------------END OF PYTHON CODE-------------------------------------


But when I run my code I get this:

-----------------------------CONSOLE OUTPUT------------------------------------
Calling conn with U:root P:PK17LP12r DB:TESTERS
Error: Database connection failed. User name or Database name may be wrong
---------------------------END OF COLSOLE OUTPUT-------------------------------

And I don't know why, since the arguments sent are the same arguments that get 
printed (telling me that the GUI the other guy coded works fine) and they are 
valid login parameters. If I hardcode the login parameters directly insetad of 
using the GUI everything goes ok and the functions executes properly; the 
following code executes nice and smooth:

--------------------------PYTHON  CODE-----------------------------------------
def compMySQL(self, user, database, password, db_level, table_level, 
column_level):
    sql_page_textview = self.mainTree.get_widget('sql_text_view')
    sql_page_textview.modify_font(pango.FontDescription("courier 10"))
    sql_page_buffer = sql_page_textview.get_buffer()

    #Gonna try hardcoding
    try:
      #print("Calling conn with U:{0} P:{1} 
DB:{2}".format(user,password,database))
      cnxOMC = mysql.connector.connect(user="root", 
password='PK17LP12r',host='localhost',database='TESTERS')
      print 'No prob with conn'
    except:
      print "Error: Database connection failed. User name or Database name may 
be wrong"
      return

    #more code ...
----------------------------END OF PYTHON CODE----------------------------------

Console output:

--------------------------------CONSOLE OUTPUT----------------------------------
No prob with conn
--------------------------------END OF CONSOLE OUTPUT---------------------------


Any ideas guys? This one is killing me.  I'm just learning Python but I imagine 
the problem to be something very easy for a seasoned python developer so any 
help would be strongly appreciated.

Thanks in advance.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to