PyMySQL Error - No attribute called 'connect' | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

PyMySQL Error - No attribute called 'connect'

I'm trying to connect input information to my PHPMyAdmin database, but it keeps saying there is no attribute called connect. Please help. I have installed pymysql correctly and even moved it to directory.

5th Aug 2020, 1:58 PM
Teo Ichim
Teo Ichim - avatar
20 Answers
5th Aug 2020, 4:03 PM
AKSHAY🇮🇳
AKSHAY🇮🇳 - avatar
+ 1
And Teo Ichim you don't have to move pymysql folder to another directory just keep it at default position i.e., lib(or libs)\site-packages\
5th Aug 2020, 4:09 PM
AKSHAY🇮🇳
AKSHAY🇮🇳 - avatar
+ 1
Yes
16th Aug 2020, 10:48 PM
Teo Ichim
Teo Ichim - avatar
0
It was really helpful, I'll try to install it their way next time.
5th Aug 2020, 2:16 PM
Teo Ichim
Teo Ichim - avatar
0
Thank you so much, have a nice day.
5th Aug 2020, 10:24 PM
Teo Ichim
Teo Ichim - avatar
0
AKSHAY it says the same thing. Please help.
6th Aug 2020, 2:39 PM
Teo Ichim
Teo Ichim - avatar
0
I did what it said
6th Aug 2020, 2:39 PM
Teo Ichim
Teo Ichim - avatar
0
Teo Ichim did you have installed latest version of pymysql...
6th Aug 2020, 3:20 PM
AKSHAY🇮🇳
AKSHAY🇮🇳 - avatar
0
Through cmd, yes.
6th Aug 2020, 3:38 PM
Teo Ichim
Teo Ichim - avatar
0
Teo Ichim see this again. https://code.sololearn.com/cY60mkVEIAVb/?ref=app Now I have installed pymysql on SL system. If you see that in the last we are getting connection error (because there is no database in localhosr). There is no problem of connection attribute
6th Aug 2020, 3:49 PM
AKSHAY🇮🇳
AKSHAY🇮🇳 - avatar
0
Okay thank you I'll check it out
6th Aug 2020, 4:12 PM
Teo Ichim
Teo Ichim - avatar
0
Let me share my code and you tell me what is wrong with it, please. Script: import pymysql as sql from tkinter import * from tkinter import ttk,messagebox from PIL import Image,ImageTk class Register: def __init__(self,root): self.root=root self.root.title("Registration Window") self.root.geometry("1350x700+0+0") self.root.config(bg="white") self.bg=ImageTk.PhotoImage(file="background.jpg") bg=Label(self.root,image=self.bg).place(x=250,y=0,relwidth=1,relheight=1) frame0=Frame(self.root,bg="#15A44B") frame0.place(x=430,y=250,width=500,height=500) #Frame frame1=Frame(self.root,bg="white") frame1.place(x=850,y=250,width=700,height=500) title=Label(frame1,text="REGISTER HERE",font=("times new roman",20,"bold"),bg="white",fg="green").place(x=50,y=30) #Row1 self.var_fname=StringVar() f_name=Label(frame1,text="First Name",font=("times new roman",15,"bold"),bg="white",fg="black").place(x=50,y=100) self.txt_fname=Entry(frame1,font=("times new roman",15),bg="lightgray",textvariable=self.var_fname) self.txt_fname.place(x=50,y=130,width=250) l_name=Label(frame1,text="Last Name",font=("times new roman",15,"bold"),bg="white",fg="black").place(x=370,y=100) self.txt_lname=Entry(frame1,font=("times new roman",15),bg="lightgray") self.txt_lname.place(x=370,y=130,width=250) #Row2 contact=Label(frame1,text="Contact No.",font=("times new roman",15,"bold"),bg="white",fg="black").place(x=50,y=170) self.txt_contact=Entry(frame1,font=("times new roman",15),bg="lightgray") self.txt_contact.place(x=50,y=200,width=250) email=Label(frame1,text="Email Address",font=("times new roman",15,"bold"),bg="white",fg="black").place(x=370,y=170) self.txt_email=Entry(frame1,font=("times new roman",15),bg="lightgray") self.txt_email.place(x=370,y=200,width=250)
6th Aug 2020, 8:40 PM
Teo Ichim
Teo Ichim - avatar
0
That is just half of it though.
6th Aug 2020, 8:41 PM
Teo Ichim
Teo Ichim - avatar
0
The main definition problem that gives connect error. def register_data(self): if self.txt_fname.get()=="" or self.txt_lname.get()=="" or self.txt_contact.get()=="" or self.txt_email.get()=="" or self.cmb_quest.get()=="" or self.txt_answer.get()=="" or self.txt_password.get()=="" or self.txt_cpassword.get()=="": messagebox.showerror("Error","All fields are required!",parent=self.root) elif self.txt_password.get()!=self.txt_cpassword.get(): messagebox.showerror("Error","Passwords do not match.") elif self.var_chk.get()==0: messagebox.showerror("Error","Please Agree to Our Terms & Conditions") else: try: con=sql.connect(host="localhost",user="root",password="",database="registration_system",cursorclass=sql.cursors.DictCursors) cur=con.cursor() cur.execute("select * from registration1 where email=%s",self.txt_email.get()) row=cur.fetchone() print(row) if row!=None: messagebox.showerror("Error","User already exists, please try another username.",parent=self.root) else: cur.execute("insert into registration1 (f_name,l_name,contact,email,question,answer,password) values(%s,%s,%s,%s,%s,%s,%s)", (self.txt_fname.get(), self.txt_lname.get(), self.txt_contact.get(), self.txt_email.get(), self.cmb_quest.get(), self.txt_answer.get(), self.txt_password.get(), )) con.commit() con.close() messagebox.showinfo("Success","Registration successful.",parent=self.root) self.clear() except Exception as es: messagebox.showerror("Err
6th Aug 2020, 8:42 PM
Teo Ichim
Teo Ichim - avatar
0
Did I just
6th Aug 2020, 8:42 PM
Teo Ichim
Teo Ichim - avatar
0
The main script: def register_data(self): if self.txt_fname.get()=="" or self.txt_lname.get()=="" or self.txt_contact.get()=="" or self.txt_email.get()=="" or self.cmb_quest.get()=="" or self.txt_answer.get()=="" or self.txt_password.get()=="" or self.txt_cpassword.get()=="": messagebox.showerror("Error","All fields are required!",parent=self.root) elif self.txt_password.get()!=self.txt_cpassword.get(): messagebox.showerror("Error","Passwords do not match.") elif self.var_chk.get()==0: messagebox.showerror("Error","Please Agree to Our Terms & Conditions") else: try: con=sql.connect(host="localhost",user="root",password="",database="registration_system",cursorclass=sql.cursors.DictCursors) cur=con.cursor() cur.execute("select * from registration1 where email=%s",self.txt_email.get()) row=cur.fetchone() print(row) if row!=None: messagebox.showerror("Error","User already exists, please try another username.",parent=self.root) else: cur.execute("insert into registration1 (f_name,l_name,contact,email,question,answer,password) values(%s,%s,%s,%s,%s,%s,%s)", (self.txt_fname.get(), self.txt_lname.get(), self.txt_contact.get(), self.txt_email.get(), self.cmb_quest.get(), self.txt_answer.get(), self.txt_password.get(), )) con.commit() con.close() messagebox.showinfo("Success","Registration successful.",parent=self.root) self.clear() except Exception as es: messagebox.showerror("Error",f"Error due to: {str(es)}",parent
6th Aug 2020, 8:43 PM
Teo Ichim
Teo Ichim - avatar
0
I meant the main problem from the whole script.
6th Aug 2020, 8:43 PM
Teo Ichim
Teo Ichim - avatar
0
Nevermind, it's all fixed.
6th Aug 2020, 9:08 PM
Teo Ichim
Teo Ichim - avatar
0
I had to switch from PyScripter to Visual Studio Code.
6th Aug 2020, 9:08 PM
Teo Ichim
Teo Ichim - avatar
0
Teo Ichim is your problem solved..
7th Aug 2020, 5:33 AM
AKSHAY🇮🇳
AKSHAY🇮🇳 - avatar