pythonmysqlmariadbpymysql

PyMySQL TypeError when connecting


I'm working with the following (very simple) MariaDB connection:

>>> from dbconfig import db_host, db_user, db_pass, db_name, system_number
>>> import pymysql as mdb
>>> print(db_host, db_user, db_pass, db_name)
some.server.co.uk my_username my_password my_db_name
>>> db = mdb.connect(db_host, db_user, db_pass, db_name)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() takes 1 positional argument but 5 were given

I feel like I have done this many times before but for some reason it is throwing this error and I'm unable to connect. I've confirmed that the details are correct and I'm able to use them to connect in a MySQL client on the same machine.

What am I missing?


Solution

  • based on official documentation you should name the parameters in the connect() function.

    connection = pymysql.connect(host='localhost',
                             user='user',
                             password='passwd',
                             database='db',
                             cursorclass=pymysql.cursors.DictCursor)
    

    Hope this helped.