gdog22
gdog22

Reputation: 1

Python Mysql class to call a stored procedure

I am very new. All of my experience is on the DB side so I am lost on the Python side of things. That said I am trying to create a class that I can use to execute stored procedures. I am using Python 3.4.3. I found a mysql class on github and simplified/modified it to make a proc call and it is not working.

mysqlquery.py
import mysql.connector, sys
from collections import OrderedDict

class MysqlPython(object):

    __host       = None
    __user       = None
    __password   = None
    __database   = None
    __procname   = None
    __inputvals  = None



    def __init__(self, host='localhost', user='root', password='', database=''):
        self.__host     = host
        self.__user     = user
        self.__password = password
        self.__database = database
    ## End def __init__

    def __open(self):
            cnx = mysql.connector.connect(self.__host, self.__user, self.__password, self.__database)
            self.__connection = cnx
            self.__session    = cnx.cursor()
    ## End def __open       

    def __close(self):
        self.__session.close()
        self.__connection.close()
    ## End def __close

    def proc(self,procname,inputvals):
        self.__open()
        self.__session.callproc(procname, inputvals)
    ## End for proc

## End class

test.py
from mysqlquery import MysqlPython

connect_mysql = MysqlPython()

result = connect_mysql.proc ('insertlink','1,www.test.com')

I get this error

TypeError: __init__() takes 1 positional argument but 5 were given

Looking at my init, it take 5 args as it should. Not sure why I am getting this. Again, I am very new so it could be a simple problem.

Thanks for any help.

G

Upvotes: 0

Views: 351

Answers (1)

Barmar
Barmar

Reputation: 781068

mysql.connector.connect() takes named arguments, not positional arguments, and you're missing the names.

cnx = mysql.connector.connect(host=self.__host, user=self.__user, password=self.__password, database=self.__database)

Upvotes: 1

Related Questions