When I try connect to mysql
with user "root"
, my application returns "Access denied for user *"ODBC"@"localhost" (using password:NO)"*
. I dnt know why this appear.
Im using Tkinter like GUI, I tested only Connection's script, its Okay.
Code Connection
import MySQLdb
class Conexao():
def __init__(self, host,user,passwd,db):
self.host = host
self.user = user
self.passwd = passwd
self.db = db
def getconnection(self):
try:
self.conn = MySQLdb.connect(host=self.host,
user = self.user,
passwd = self.passwd,
db = self.db)
print "Connected"
return self.conn.cursor()
except MySQLdb.Error,e:
print " error "+ str(e[1])
return e
Code App
from Tkinter import *
import sys
sys.path.insert(0,'C:\\Users\\felipe.cunha\\Documents\\project')
from conexao.conexao import Conexao
"""
b.execute("select * from setor")
>>> b.fetchall()
"""
class View(Frame):
def __init__(self,master = None):
Frame.__init__(self)
self.master.title("teste")
self.create_menu()
def create_menu(self):#,width = self.width,height = self.height):
host = "localhost"
label_menu = Label(self.master,text = 'Login')
label_menu.pack()
entrada_menu_login = Entry(self.master)# user
entrada_menu_senha = Entry(self.master, show = "*")# passwd
conn = Conexao(host,entrada_menu_login.get(),entrada_menu_senha.get(),"dsti")
#conn = Conexao(host,"root","d04m10","dsti")
btn_login = Button(self.master,text="Logar",command = conn.getConnection)#self.show_entry_fields)
entrada_menu_login.pack()
entrada_menu_senha.pack()
btn_login.pack()
def show_entry_fields(self):
print(self.entrada_menu_login.get(), self.entrada_menu_senha.get())
app = View()
app.mainloop()
Like Bryan said, that may be the issue with your code, instead of making the button call conn.getConnection() directly, try an approach, where you save the entry variables into 'self' and then when the button is invoked, you create the connection at that time.
The code would look something like -