Skip to content

Commit

Permalink
Encoding for MySQL non-ascii username/password (#64)
Browse files Browse the repository at this point in the history
* Encoding to handle special chars in username/password.
* Python2/3 compatibility.
  • Loading branch information
talonx authored and rshivane committed Aug 23, 2018
1 parent 852b042 commit ab8d48d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion collectors/0/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,18 @@ def _reconnect(self):
self.cursor = self.db.cursor()


def unicode_text(txt):
if not isinstance(txt, str):
return str(txt.encode('utf-8')) # Python2
return txt # Python3


def mysql_connect(conn_props):
"""Connects to the MySQL server using the specified connection properties."""
return MySQLdb.connect(host=conn_props[0],
port=conn_props[1],
user=conn_props[2], passwd=conn_props[3])
user=unicode_text(conn_props[2]),
passwd=unicode_text(conn_props[3]))


def todict(db, row):
Expand Down

0 comments on commit ab8d48d

Please sign in to comment.