Quantcast
Channel: Active questions tagged charset - Stack Overflow
Viewing all articles
Browse latest Browse all 59

MySQL Connector / CharacterSet / two connections

$
0
0

I am facing a problem using python, mysql.connector (8.1.0) and trying to open 2 connections on 2 different servers:

If I run :

from mysql.connector import MySQLConnectionif __name__ in '__main__':    # A    try:        c1 = MySQLConnection(            host='host1',            user='*',            password='*',            database='A'        )        c1.close()    except Exception as e:        print(e)    finally:        print('c1')    # B    try:        c2 = MySQLConnection(            host='host2',            user='*',            password='*',            database='B'        )        c2.close()    except Exception as e:        print(e)    finally:        print('c2')

I got exception : Character set 'utf8' unsupported for c2

If I run only part B, it's Ok. It's as if something was set globally after the first connection.

any idea?

EDIT: Got it ! CharacterSet.desc is a class variable set at begining.

from mysql.connector import MySQLConnection as MySQLConnectionfrom mysql.connector.constants import CharacterSetif __name__ in '__main__':    desc = CharacterSet.desc.copy()    try:        c1 = MySQLConnection(            host='host1',            user='*',            password='*',            database='A'        )        c1.close()    except Exception as e:        print(e)    finally:        print('c1')    CharacterSet.desc = desc    try:        c2 = MySQLConnection(            host='host2',            user='*',            password='*',            database='B'        )        c2.close()    except Exception as e:        print(e)    finally:        print('c2')

It works now


Viewing all articles
Browse latest Browse all 59

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>