Bishnu Bhattarai
Bishnu Bhattarai

Reputation: 2910

TypeError: an integer is required in python mysql

I want to simply access the database of mysql through python.But when I am running this code :

import MySQLdb
db = MySQLdb.connect(host = "127.0.0.1",
                     port = "3306",
                      user="Bishnu",
                      passwd = "Pulchowk",
                      db = "student")
cursor =db.cursor()
cursor.execute("select * from basic_info")
numrows = int(cursor.rowcount)
for x in range(0,numrows):
    row = cursor.fetchall()
    print row[0],"-->",row[1]
db.cose()

It gives an error as :

Traceback (most recent call last):
  File "C:\Users\Bishnu\Desktop\database", line 6, in <module>
    db = "student")
  File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
TypeError: an integer is required

What is that TypeError : an integer is required

Why such problem occurs? To run this code I have got 3 problems but luckily this forum solved my two problems, I think it will also be solved ?

Upvotes: 1

Views: 6759

Answers (1)

dvz
dvz

Reputation: 161

db = MySQLdb.connect(host = "127.0.0.1",
                 port = "3306",
                  user="Bishnu",
                  passwd = "Pulchowk",
                  db = "student")

try replacing:

port = "3306"

with

port = 3306

(remove the quotes)

Upvotes: 16

Related Questions