Skip to content Skip to sidebar Skip to footer

Python Mysql Connector Returns Bytearray Instead Of Regular String Value

I am loading data from one table into pandas and then inserting that data into new table. However, instead of normal string value I am seeing bytearray. bytearray(b'TM16B0I8') it s

Solution 1:

For some reason the Python MySql connector only returns bytearrys, (more info in (How return str from mysql using mysql.connector?) but you can decode them into unicode strings with

var_ticket_id = row['ticket_id'].decode()
var_history_date = row['history_date'].decode()

Solution 2:

Make sure you are using the right collation, and encoding. I happen to use UTF8MB4_BIN for one of my website db tables. Changed it to utf8mb4_general_ci, and it did the trick.

Post a Comment for "Python Mysql Connector Returns Bytearray Instead Of Regular String Value"