title: Python and MySQLdb - data not inserted, data conversion error too
body: <p>I am trying to do a simple </p>
  
  <ul>
  <li>INSERT into a localhost MySQL 5.7 db </li>
  <li>with a Python 2.7 script</li>
  </ul>
  
  <p>Nothing fancy but that is exactly the result I get - nothing.</p>
  
  <p>I tested the darn thing bit by bit in a separate test script, no errors raised but no data inserted into table, as well. Problem occurs at the first SQL variable (probably) and there is one error in the last try/catch. </p>
  
  <p>I guess I am not doing the <strong>data type conversion</strong> correctly? </p>
  
  <p>Here is the code:</p>
  
  <pre><code>#!/usr/bin/python
  
  import MySQLdb
  import pandas as pd 
  import numpy as np 
  import xlwings as xw
  
  # ---------- Connect to Excel sheet, get data (list of lists)
  wb = xw.Workbook('/users/edchigliak/sites/xlwings/baza.xlsx')
  data = xw.Range('dimensions', 'A2:F71').value
  
  # ---------- Open database connection, insert data into table
  db = MySQLdb.connect("localhost","root","/pass/","budgeteer")
  cursor = db.cursor()
  </code></pre>
  
  <p>Following <strong>sql</strong> and <strong>for</strong> could be written badly:</p>
  
  <pre><code>sql = """INSERT INTO dimensions(dimension, dimType, abbreviation, translationHr, code) VALUES (%s, %d, %s, %s, %d)"""  
  
  for row in data:
      try:
          cursor.execute(sql, row)
          db.commit()
      except:
          db.rollback()
  
  
  # ---------- Check if INSERT successful
  sql = """SELECT * FROM dimensions"""
  
  try:
      cursor.execute(sql)
  
      # ---------- Fetch all the rows in a list of lists
      results = cursor.fetchall()
  
  for row in cursor:
  
      id = row[0]
      dimension = row[1]
      dimType = row[2]
      abbreviation = row[3]
      translationHr = row[4]
      code = row[5]
  </code></pre>
  
  <p>Here is the error, goes to "except":</p>
  
  <blockquote>
    <p>Error: unable to fetch data.</p>
  </blockquote>
  
  <pre><code>    # Now print fetched result
      print "Dim. ID: %d, Dim.: %s, Dim. type: %d, Abbrev.: %d, Translat.: %s, Code: %d" % (id, dimension, dimType, abbreviation, translationHr, code)
  
  except:
      print "Error: unable to fetch data"
  
  db.close()
  </code></pre>
  
  <p>And if I remove try block:</p>
  
  <blockquote>
    <p>python git:master ❯ python proba.py<br>
    Traceback (most recent call last):<br>
    File "proba.py", line 47, in <br>
    print "Dim. ID: %d, Dim.: %s, Dim. type: %d, Abbrev.: %d, Translat.: %s,
    Code: %d" % (id, dimension, dimType, abbreviation, translationHr, code)
    TypeError: %d format: a number is required, not str<br>
    python git:master ❯      </p>
  </blockquote>
  
  <p>For what it's worth, this is the sample of a list that gets read from Excel in the beginning of the script (maybe 'None' is making problems?):</p>
  
  <blockquote>
    <p>[1.0, u'austria', 1.0, u'at', None, 4.0]<br>
    [2.0, u'belgium', 1.0, u'be', None, 7.0]<br>
    [3.0, u'czech', 1.0, u'cz', None, 9.0]</p>
  </blockquote>