0

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

2
  • After init declaration add : character Commented Sep 13, 2016 at 19:14
  • 1
    Please drop all those double underscore prefixes. They don't do what you think and will almost certainly cause you problems in the future. Commented Sep 13, 2016 at 19:17

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.