1

So, I just got started today with python. I installed the python-mysql.connector so I can start writing some queries and within python work with the result, and then output some data to an lcd screen.

Right know this is what I have....

#!/usr/bin/python

import Adafruit_CharLCD
import mysql.connector

class LCDTests:

    def __init__(self):

        self.lcd = Adafruit_CharLCD;
        #self.lcd.begin(16,1);

        try:
            cnx = mysql.connector(user = '', password='' database='', host='')
        except mysql.connector.Error, e:
            try:
                print "MySQL Error [%d]: %s" % (e.args[0], e.args[1])
            except IndexError:
                print "MySQL Error: %s" % str(e)            
        else:
                cnx.close()

    def run(self):
            print('alex')
            #lcd.message('loading...');

test = LCDTests()
test.run()

But when ever I run ./test.py I keep getting the following output:

Traceback (most recent call last):
  File "./test.py", line 31, in <module>
    test = LCDTests()
  File "./test.py", line 16, in __init__
    cnx = mysql.connector(user = '...', password='...', database='...', host='...')
TypeError: 'module' object is not callable

Nothing what I found, while searching for the issue, really helped me fixing the issue... any ideas where the issue might be?

3 Answers 3

4

mysql.connector.connect(...) not mysql.connector(...)

module docs will probably be a good resource for you.

Sign up to request clarification or add additional context in comments.

Comments

2

The proper syntax is mysql.connector.connect(user, password, host, database).

Comments

0

You have a typo. Currently you are referencing the module mysql.connector not the Connect class in the module. try

mysql.connector.Connect(...)

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.