This is the Python code where I am establishing a database connection. But I am getting a type error in my code. What is the issue?
import pymysql
connnection = pymysql.connect("localhost", "root", "", "dbname")
Error:
Traceback(most recent call last):
File "c:/Users/Dell/Desktop/Full Code/COllectUrls.py", line 21, in <module>
connnection = pymysql.connect("localhost", "root", "", "dbname")
TypeError: __init__() takes 1 positional argument but 5 were given
This solves the problem.
import pymysql
# Connect to the database
connection = pymysql.connect(host='localhost',
user='user',
password='passwd',
database='db',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
This will work for 3.x versions.
import pymysql
connection = pymysql.connect(host='localhost', user='root', password='', database='db_emp', charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor)
cursor = connection.cursor()
cursor.execute("SELECT VERSION()")
data = cursor.fetchone()
print ("Database version : %s " % data)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With