python,mysql,mysql-connector,mysql-connector-python , Python Exception: RuntimeError: maximum recursion depth exceeded/unprintable runtime error

Python Exception: RuntimeError: maximum recursion depth exceeded/unprintable runtime error


Tag: python,mysql,mysql-connector,mysql-connector-python

I'm getting this exception randomly on a script that receives items to insert into a mysql database using mysql-connector:

Traceback (most recent call last):
  File "/opt/python/current2/lib/python2.7/logging/", line 77, in emit
Traceback (most recent call last):
  File "/opt/python/current2/lib/python2.7/logging/", line 77, in emit
Traceback (most recent call last):
  File "/opt/python/current2/lib/python2.7/logging/", line 79, in emit
Traceback (most recent call last):
  File "/opt/python/current2/lib/python2.7/logging/", line 79, in emit
Traceback (most recent call last):
  File "/opt/python/current2/lib/python2.7/logging/", line 79, in emit
    logging.FileHandler.emit(self, record)
  File "/opt/python/current2/lib/python2.7/logging/", line 930, in emit
    StreamHandler.emit(self, record)
  File "/opt/python/current2/lib/python2.7/logging/", line 874, in emit
  File "/opt/python/current2/lib/python2.7/logging/", line 801, in handleError
    None, sys.stderr)
  File "/opt/python/current2/lib/python2.7/", line 124, in print_exception
    _print(file, 'Traceback (most recent call last):')
RuntimeError: maximum recursion depth exceeded
Logged from file, line 47

I also occasionally get:

Traceback (most recent call last):
  File "/opt/python/current2/lib/python2.7/logging/", line 77, in emit
Traceback (most recent call last):
  File "/opt/python/current2/lib/python2.7/logging/", line 77, in emit
    if self.shouldRollover(record):
  File "/opt/python/current2/lib/python2.7/logging/", line 156, in shouldRollover
    msg = "%s\n" % self.format(record)
  File "/opt/python/current2/lib/python2.7/logging/", line 723, in format
    return fmt.format(record)
  File "/opt/python/current2/lib/python2.7/logging/", line 464, in format
    record.message = record.getMessage()
  File "/opt/python/current2/lib/python2.7/logging/", line 322, in getMessage
    if not isinstance(msg, basestring):
Traceback (most recent call last):
  File "/opt/python/current2/lib/python2.7/logging/", line 79, in emit
    logging.FileHandler.emit(self, record)
  File "/opt/python/current2/lib/python2.7/logging/", line 930, in emit
    StreamHandler.emit(self, record)
  File "/opt/python/current2/lib/python2.7/logging/", line 874, in emit
RuntimeError: <unprintable RuntimeError object>
Logged from file, line 47

The code:

import sys
import datetime
import mysql.connector
import config
from logwatch import log
import time, os

class DBConnection:
    _dbconn = None

    def get_instance():
        if not DBConnection._dbconn:
            DBConnection._dbconn = DBConnection()
        return DBConnection._dbconn

    def __init__(self):
        self.connection = None

    def connect(self):
        if not self.connection:
            self.connection = mysql.connector.connect(**config.CONFIG)

    def get_cursor(self):
        retries = 2
        while retries > 0:
                cursor = self.connection.cursor(buffered=True)
                return cursor
            except mysql.connector.errors.InterfaceError, iErr:
                log.error("%s: Connection failed. Retrying. " % iErr)
                self.connection = None
                retries -= 1
                if retries == 0:

    def execute(self, query, params=None):
        cursor = self.get_cursor()
        cursor.execute(query, params)
        return cursor.rowcount

    def commit(self):
        except Exception, cExc:
            log.error("Error committing the operation to MySQL: %s" % cExc)

def foo(**kwargs):
    dml = None
    values = None
    rows = None

    if kwargs['action'] == "check":
        dml = "SELECT `log_type` FROM `register` WHERE `record_num` = \
        %s AND `log_type` IN ('1', '3')" % kwargs['record_num']"%s %s Checking if record exists in F/U or SA of db: %s" % (kwargs['rectype'], kwargs['record_num'], dml))

    if kwargs['action'] == "moveto":
        sections = ['Trash','Follow up','Problem','Scheduled Actions','Information']
        if kwargs['section'] == 0:
            dml = "UPDATE `register` SET `log_type` = %s WHERE `record_num` = %s"
            values = (kwargs['section'], kwargs['record_num'])
            dml = "UPDATE `register` SET `log_type` = %s, `comments` = %s WHERE `record_num` = %s"
            values = (kwargs['section'], kwargs['status'], kwargs['record_num'])"%s %s Moving to section '%s' %d: %s" %\
        (kwargs['rectype'], kwargs['record_num'], sections[kwargs['section']], kwargs['section'], (dml % values) ))

    if kwargs['action'] == "schedule":
        yyyymmdd = datetime.datetime.strptime(kwargs['start_date'], '%d%b%y').strftime('%Y-%m-%d')
        start_hour = kwargs['start_time'][0:2]
        dml = "INSERT INTO `register` (`record_num`,`title`,`sch_date`, \
        `sch_time`,`rectype`,`log_type`,`user_id`,`entry`,`site`,`comments`,`category`) VALUES \
        (%s, %s, %s, %s, %s, 3, 'FOO', 2, %s, %s, 63)"
        values = (kwargs['record_num'], kwargs['title'], yyyymmdd, kwargs['start_time'], kwargs['rectype'], get_site_flag(start_hour), kwargs['comment'])"%s %s Adding to scheduled actions up for review: %s" % (kwargs['rectype'], kwargs['record_num'], (dml % values) ))

    if kwargs['action'] == "update_to_schedule":
        yyyymmdd = datetime.datetime.strptime(kwargs['start_date'], '%d%b%y').strftime('%Y-%m-%d')
        start_hour = kwargs['start_time'][0:2]
        dml = "UPDATE `register` SET `title` = %s,`sch_date` = %s, \
        `sch_time` = %s,`rectype` = %s,`log_type` = '3',`user_id` = 'FOO', \
        `entry` = '2',`site` = %s WHERE `record_num` = %s LIMIT 1"
        values = (kwargs['title'], yyyymmdd, kwargs['start_time'], kwargs['rectype'], get_site_flag(start_hour), kwargs['record_num'])"%s %s Updating to scheduled actions for review: %s" % (kwargs['rectype'], kwargs['record_num'], (dml % values) ))

    if kwargs['action'] == "update_to_follow":
        dml = "UPDATE `register` SET `title` = %s,`rectype` = %s, \
        `log_type` = '1',`user_id` = 'FOO', `entry` = '2', \
        `site` = 'M' WHERE `record_num` = %s LIMIT 1"
        values = (kwargs['title'], kwargs['rectype'], kwargs['record_num'])"%s %s Updating to follow up for review: %s" % (kwargs['rectype'], kwargs['record_num'], (dml % values) ))

    if kwargs['action'] == "follow-up":
        dml = "INSERT INTO `register` (`record_num`,`title`,`sch_date`, \
        `rectype`,`log_type`,`user_id`,`entry`,`site`,`comments`,`category`) VALUES \
        (%s, %s, NOW(), %s, 1, 'FOO', 2, 'M',%s, 63)"
        values = (kwargs['record_num'], kwargs['title'], kwargs['rectype'], kwargs['comment'] + ', Please follow-up')"%s %s Adding to follow up for review: %s" % (kwargs['rectype'], kwargs['record_num'], (dml % values) ))    
            connection = DBConnection.get_instance()
            rows = connection.execute(dml, values)
  "%s %s EXECUTE affected %s rows." % (kwargs['rectype'], kwargs['record_num'], rows))
        log.error("Error: could not execute %s on db for %s %s.,%s" % ((dml % values), kwargs['rectype'], kwargs['record_num'], str(sys.exc_info())))
    return rows

line 47 being:

log.error("Error committing the operation to MySQL: %s" % cExc)

Am I supposed to be encapsulating this in something else? Sorry I don't know python, I know Java, I'm just trying to fix this script that I've adopted. There's other random exceptions as well but one step at a time, these seem to stream in at every commit? Trying to figure out if it's the cause of why the script seems to fail to insert into the database under heavy stress, the commit is a new addition to this script which was someone else's attempted fix.

Whenever the script fails to insert into the database we also get:

(<class 'mysql.connector.errors.OperationalError'>, OperationalError(), <traceback object at 0x2aaaaaf76050>)  
(<class 'mysql.connector.errors.InterfaceError'>, InterfaceError(), <traceback object at 0x2aaaaaf75ab8>)

This shows up in the official logging via that log.error line above instead of the stdout error file where the exceptions are dumped.

Any help would be greatly appreciated, thanks.


This looks like the culprit:

def commit(self):
    except Exception, cExc:
        log.error("Error committing the operation to MySQL: %s" % cExc)

This is an infinite loop until your recursion depth exceeds your system's limit (typically 1000). At the end since you are catching all exceptions, you end up at

log.error("Error committing the operation to MySQL: %s" % cExc)


# self.commit() - WRONG

Also consider not catching all exceptions after the commit (Considered very bad practice). Replace with the base class for all mysql exceptions instead:

except mysql.connector.Error as e:
    log.error("Error committing the operation to MySQL: %s" % e)


Calling function and passing arguments multiple times

I want to call the function multiple time and use it's returned argument everytime when it's called. For example: def myfunction(first, second, third): return (first+1,second+1,third+1) 1st call: myfunction(1,2,3) 2nd call is going to be pass returned variables: myfunction(2,3,4) and loop it until defined times. How can I do such loop?...

I Want to fetch SQL Records in MySQL of current Year

I am using the query SELECT count(enq.`enquiryId`), Month(enq.`date`), Year(enq.`date`) FROM enquiry enq GROUP BY MONTH(enq.`date`) But I get all year records. I just want to get Current or any input year(At Runtime) records. Please help....

Trying to rewrite mysql_* to pdo

First of all I should say that I started to learn PDO and trying to rewrite some old mine codes. Here is one that I found on tutorial for a jquery/ajax/pdo/mysql comment system which is working. This is the mysql_* part which I'm trying to rewrite -> file submit.php which...

Using counter on array for one value while keeping index of other values

After reading the answers on this question How to count the frequency of the elements in a list? I was wondering how to count the frequency of something, and at the same time retreive some extra information, through something like an index. For example a = ['fruit','Item#001'] b = ['fruit','Item#002']...

Displaying a 32-bit image with NaN values (ImageJ)

I wrote a multilanguage 3-D image denoising ImageJ plugin that does some operations on an image and returns the denoised image as a 1-D array. The 1-D array contains NaN values (around the edges). The 1-D array is converted back into an image stack and displayed. It is simply black....

Ignore Group if LIMIT is not reached in MySQL

I am working on a rather tricky SQL for my level of knowledge. I have searched and searched for an answer but haven't came across anything. Hopefully someone can shed some light on this. How can you stop SQL from outputting group of rows if the limit set is not...

Twilio Client Python not Working in IOS Browser

I have created a simple twilio client application to make phone calls from Web Browser to phones. I used a sample Flask app to generate a secure Capability Token and used twilio.min.js library to handle calls from my HTML. The functionality works fine in Computer Browsers ans Android Phone Browsers,...

How to change the IP address of Amazon EC2 instance using boto library

How can I assign a new IP address (or Elastic IP) to an already existing AWS EC2 instance using boto library.

How to check for multiple attributes in a list

I am making a TBRPG game using Python 2.7, and i'm currently making a quest system. I wanted to make a function that checks all of the quests in a list, in this case (quests), and tells you if any of of the quests in the list have the same...

group indices of list in list of lists

I am looking for an elegant solution for the following problem. I have a list of ints and I want to create a list of lists where the indices with the same value are grouped together in the order of the occurrences of said list. [2, 0, 1, 1, 3,...

SQLAlchemy. 2 different relationships for 1 column

I have a simple many-to-many relationship with associated table: with following data: matches: users: users_mathces: ONE user can play MANY matches and ONE match can involve up to TWO users I want to realize proper relationships in both "Match" and "User" classes users_matches_table = Table('users_matches', Base.metadata, Column('match_id', Integer, ForeignKey('', onupdate="CASCADE",...

How to call MySQL view in Struts2 or Hibernate

I have a view in MySQL database CREATE VIEW CustInfo AS SELECT a.custName, a.custMobile, b.profession, b.companyName, b.annualIncome FROM customer a INNER JOIN cust_proffessional_info b ON a.cust_id=b.cust_id Is there any way that i can call this view using Struts2 or in Hibernate. I have tried to search it but could not...

How to search images by name inside a folder?

I have a MySQL table with a column "rounds" and each "rounds" has his own photos. Exemple round1 has photos from start=380 end=385. This means it has 6 photos and the name of the photos contains 380,381,382,383,384 or 385 inside. I use this PHP code to display the photos from...

Pandas - Dropping multiple empty columns

I have some tables where the first 11 columns are populated with data, but all columns after this are blank. I tried: df=df.dropna(axis=1,how='all') which didn't work. I then used: df = df.drop(df.columns[range(11,36)], axis=1) Which worked on the first few tables, but then some of the tables were longer or shorter...

If I export my database with phpmyadmin will it lock my tables or take my database down?

I want to create a backup of my database using the phpmyadmin export function. the database can't have any down time so I need to know if running a database export will take the database down? I've looked on-line but all I get is instructions on how to export. No...

How do I read this list and parse it?

I'm using requests and the output I get from the sites API is a list, I've been stuck trying to parse it to get the data from it. I use r = requests.get(urlas, params=params) r.json() to get the data I want. Here is a snippet of the list [{'relation_type': None,...

In sklearn, does a fitted pipeline reapply every transform?

Apologies if this is obvious but I couldn't find a clear answer to this: Say I've used a pretty typical pipeline: feat_sel = RandomizedLogisticRegression() clf = RandomForestClassifier() pl = Pipeline([ ('preprocessing', preprocessing.StandardScaler()), ('feature_selection', feat_sel), ('classification', clf)]),y) Now when I apply pl on a new set, pl.predict(X_classify); is RandomizedLogisticRegression going...

MySQL - How can I know my query is tuned?

I'm creating a DB from scratch and I'm trying to create queries with performance in mind. For test purpose I filled my tables with test data. My query needs to join 3 tables: 2 with millions of rows and the third with hundred thousands rows. How can I know my...

Identify that a string could be a datetime object

If I knew the format in which a string represents date-time information, then I can easily use datetime.datetime.strptime(s, fmt). However, without knowing the format of the string beforehand, would it be possible to determine whether a given string contains something that could be parsed as a datetime object with the...

MySQL: Select several rows based on several keys on a given column

I have this mysql table structure: ------------------------------------ | item_id | meta_key | meta_value | ------------------------------------ 159 category Bungalow 159 location Lagos 159 price 45000 160 category Bungalow 160 location Abuja 160 price 53500 ... 350 category Bungalow 350 location Lagos 350 price 32000 What I'd like to do is select...

Strange Behavior: Floating Point Error after Appending to List

I am writing a simple function to step through a range with floating step size. To keep the output neat, I wrote a function, correct, that corrects the floating point error that is common after an arithmetic operation. That is to say: correct(0.3999999999) outputs 0.4, correct(0.1000000001) outputs 0.1, etc. Here's...

Python: histogram/ binning data from 2 arrays.

I have two arrays of data: one is a radius values and the other is a corresponding intensity reading at that intensity: e.g. a small section of the data. First column is radius and the second is the intensities. 29.77036614 0.04464427 29.70281027 0.07771409 29.63523525 0.09424901 29.3639355 1.322793 29.29596385 2.321502 29.22783249...

C# - Can't connect to remote MySQL server

My problem is that I can't connect to my website remote MySQL server. I have read all answers in, but I can't find right answer. Here's my C# code: using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { SqlConnection...

PHP: While loop not working after adjusting SELECT for SQL injection prevention

I am trying to set up PHP queries for MySQL in a way to prevent SQL injection (standard website). I had a couple of INSERT queries where changing this worked well but on the following SELECT I keep getting an error since the update and it looks like the while...

Notice: Array to string conversion in “path of php file” on line 64

PHP CODE -: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html xmlns=""> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $rows =0; $fp = fopen("leave1.csv","r"); if($fp){ while(!feof($fp)){ $content = fgets($fp); if($content) $rows++; } } fclose($fp); //echo $rows; $_SESSION['rows'] = $rows; ?>...

Python - Opening and changing large text files

I have a ~600MB Roblox type .mesh file, which reads like a text file in any text editor. I have the following code below: mesh = open("file.mesh", "r").read() mesh = mesh.replace("[", "{").replace("]", "}").replace("}{", "},{") mesh = "{"+mesh+"}" f = open("p2t.txt", "w") f.write(mesh) It returns: Traceback (most recent call last): File...

Retrieve Values As Column

I've the following table in my PHPMYADMIN The desired output is headline                              impressions              clicks Buy A new Iphone                 ...

Find the tf-idf score of specific words in documents using sklearn

I have code that runs basic TF-IDF vectorizer on a collection of documents, returning a sparse matrix of D X F where D is the number of documents and F is the number of terms. No problem. But how do I find the TF-IDF score of a specific term in...

Count function counting only last line of my list

Count function counting only last line of my list N = int(raw_input()) cnt = [] for i in range(N): string = raw_input() for j in range(1,len(string)): if string[j] =='K': cnt.append('R') elif string[j] =='R': cnt.append('R') if string[0] == 'k': cnt.append('k') elif string[0] == 'R': cnt.append('R') print cnt.count('R') if I am giving...

concatenate field names in a mysql update with inner join

Concatenating two field names from different tables using INNER JOIN during UPDATE statement. I am trying to concatenate two field names in a mysql update statement. This is what I have so far, needless to say it isn't working, any suggestions would be much appreciated. UPDATE products INNER JOIN sub_categories...

Sum of two variables in RobotFramework

I have two variables: ${calculatedTotalPrice} = 42,42 ${productPrice1} = 43,15 I executed ${calculatedTotalPrice} Evaluate ${calculatedTotalPrice}+${productPrice1} I got 42,85,15 How can I resolve it?...

How to remove structure with python from this case?
How to remove "table" from HTML using python? I had case like this: paragraph = ''' <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quidem molestiae consequuntur officiis corporis sint.<br /><br /> <table> <tr> <td> text title </td> <td> text title 2 </td> </tr> </table> <p> lorem ipsum</p> ''' how...

MySQL substring match using regular expression; substring contain 'man' not 'woman'

I have an issue while I fetch data from database using regular expression. While I search for 'man' in tags it returns tags contains 'woman' too; because its substring. SELECT '#hellowomanclothing' REGEXP '^(.)*[^wo]man(.)*$'; # returns 0 correct, it contains 'woman' SELECT '#helloowmanclothing' REGEXP '^(.)*[^wo]man(.)*$'; # returns 0 incorrect, it can...

Sort when values are None or empty strings python

I have a list with dictionaries in which I sort them on different values. I'm doing it with these lines of code: def orderBy(self, col, dir, objlist): if dir == 'asc': sorted_objects = sorted(objlist, key=lambda k: k[col]) else: sorted_objects = sorted(objlist, key=lambda k: k[col], reverse=True) return sorted_objects Now the problem...

Can Rails deal with DB uniqueness without index?

I see add_index ~ unique: true statement in schema.rband think uniqueness is constraint for table, not for index.Using index is one of way realizing uniqueness, Programmer should not designate to the RDBMS "how" and index quicken searching but take costs inserting. In fact, is there another way to keep uniqueness...

represent an index inside a list as x,y in python

I have a list which contains 1000 integers. The 1000 integers represent 20X50 elements of dimensional array which I read from a file into the list. I need to walk through the list with an indicator in order to find close elements to each other. I want that my indicator...

How do variables inside python modules work?

I am coming from a Java background with Static variables, and I am trying to create a list of commonly used strings in my python application. I understand there are no static variables in python so I have written a module as follows: import os APP_NAME = 'Window Logger' APP_DATA_FOLDER_PATH...

The event loop is already running

I have the following 5 files: # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui try: _fromUtf8 = QtCore.QString.fromUtf8 except AttributeError: def _fromUtf8(s): return s try: _encoding = QtGui.QApplication.UnicodeUTF8 def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig, _encoding) except AttributeError: def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig)...

How does the class_weight parameter in scikit-learn work?

I am having a lot of trouble understanding how the class_weight parameter in scikit-learn's Logistic Regression operates. The Situation I want to use logistic regression to do binary classification on a very unbalanced data set. The classes are labelled 0 (negative) and 1 (positive) and the observed data is in...

Replace nodejs for python?

i'm working in a HTML5 multiplayer game, and i need a server to sync player's movement, chat, battles, etc. So I'm looking for ways to use python instead nodejs, because i have I have more familiarity with python. The server is simple: var express = require('express'); var app = express();...

compare today's date with unix timestamp value in database

In database I am storing date value unix timestamp value for e.g.'1434952110' using time() now I am trying to compare todays value with this value as below $jobpostdate = date("Y-m-d");//today's date passing in database to compare query $sql = "SELECT jsp_title, jsp_subtitle, jsp_desc, jsp_location, jsp_date "; $sql .= "FROM js_projects...

MySQL Query returning strange values

The query is supposed to do the following: Obtain the question and associated answers based on the identification number of the question. (In this case the identification number is called account_id. Order them so that each question (and it's appropriate answers) are lined up in order. The query: SELECT *...

Php Mysql Query not working properly

I have a table name tblnetworkstatus and I have 11 columns Id issue_name affected_server affected_service issue_type priority duration status start_date end_date description I am getting id in affected_server and affected_service which I am storing in my DB, now I have three situations Either both affected_server and affected_service has been selected...

PHP / MySQLi: How to prevent SQL injection on INSERT (code partially working)

I am new to PHP and hope someone can help me with this. I would like to store two values (an email and a password) in a MySQL db using PHP. The input is passed to the PHP page via Ajax in jQuery (through an onclick event on a website)....

Python recursive function not recursing

I'm trying to solve a puzzle, which is to reverse engineer this code, to get a list of possible passwords, and from those there should be one that 'stands out', and should work function checkPass(password) { var total = 0; var charlist = "abcdefghijklmnopqrstuvwxyz"; for (var i = 0; i...

Pandas Dataframe Complex Calculation

I have the following dataframe,df: Year totalPubs ActualCitations 0 1994 71 191.002034 1 1995 77 2763.911781 2 1996 69 2022.374474 3 1997 78 3393.094951 I want to write code that would do the following: Citations of currentyear / Sum of totalPubs of the two previous years I want something to...

How do I display my mysql table column headers in my php/html output?

2 Questions... Scenario: I would like to query my database table via a form and then display the results that occur(if there are results) and my current situation is that it does work but it clears the form completely and leaves my to an empty page with just the results...

How to program a recurring billing/invoice system using PHP and MySQL

I have already programmed a basic invoicing system using PHP/MySQL which has a table structure as follows; Invoice table; invoice_id, invoice_date, customer_id, etc Invoice line table; invoice_line_id, invoice_id, quantity, price, description, etc I need the system to automatically generate future invoices at set intervals (for example every 1 week or...

trying to understand LSH through the sample python code

the concise python code i study for is here Question A @ line 8 i do not really understand the syntax meaning for "res = res << 1" for the purpose of "get_signature" Question B @ line 49 (SOLVED BY myself through another Q&A) "xor = r1^r2" does not really...

C# MySQL Parameters.AddWithValue

Hello I found this code snippet for Adding Values to MySQL Commands in C# MySqlCommand command = connection.CreateCommand(); command.CommandText = "INSERT INTO tb_mitarbeiter (Vorname) VALUES (?name)"; command.Parameters.AddWithValue("?name", mitarbeiter); connection.Open(); command.ExecuteNonQuery(); Now I want to add data to more than one coloumn, but if i try it like this: command.Parameters.AddWithValue("?id", Projektid,...