_mysql_exceptions.OperationalError: (1271, "Illegal mix of collations for operation ' IN '") in python

Viewed 735

I have a MYSQL query in python. It worked fine. But, after deleting some tuple in the table, it makes following error.

_mysql_exceptions.OperationalError: (1271, "Illegal mix of collations for operation ' IN '")

Following is my code so far.

with open('out.csv', 'rb') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
    text=(row['text'])
    emotion = (row['emotion'])
    my_list = (text, emotion)
    my_array = np.asarray(my_list)
    sentence = (text.lower())
    w_tokenize = (word_tokenize(sentence))

    negation_words = [w for i, w in enumerate(w_tokenize) if i and (
        w_tokenize[i - 1] in ["not", "never", "no", "nobody", "nothing", "neither", "doesn't", "isn't", "wasn't",
                        "shouldn't", "wouldn't", "couldn't", "won't", "can't", "don't", "didn't"])]

    if w_tokenize== []:
        Value = ''
    else:
        cursor = conn.cursor()
        format_strings = ','.join(['%s'] * len(w_tokenize))
        cursor.execute("SELECT emotion_type FROM emotion WHERE key_word IN  (%s)" % format_strings,
                       tuple(w_tokenize))
        results = [res[0] for res in cursor.fetchall()]
        if results:
            frequencies = Counter(results)
            Value = max(frequencies, key=frequencies.get)
        else:
            Value = ''

But I couldn't find the solution for that. Can any one help me.

1 Answers
Related