I am using Apache Airflow, and this is a function in my PythonOperator to collect the data. And my data has arabic strings. Now when I execute the query without setting character to utf8 I get "???? ???". And so I did this set upbelow. But still the issue is not solved, I get at the end "ÙØÙØ¯ اÙÙØ§Ø¬Ø±Ù"
In arabic it supposed to be "محمد الهاجرى"
query = "select * from test_sample limit 1;"
source_hook = MySqlHook(mysql_conn_id='mysql_conn', schema='mysql')
source_conn = source_hook.get_conn()
source_cursor = source_conn.cursor()
source_cursor.execute("SET NAMES utf8;")
source_cursor.execute("SET CHARACTER SET utf8;")
source_cursor.execute("SET character_set_connection=utf8;")
source_cursor.execute(query)
columns = [col[0] for col in source_cursor.description]
records_data = [dict(zip(columns, row)) for row in source_cursor.fetchall()]
record = records_data[0]
test_a = record['name']
print(test_a)
You can check in this link here , when you paste ÙØÙØ¯ اÙÙØ§Ø¬Ø±Ù
and you can see the arabic output above محمد الهاجرى
. But I'm not able to get it in my code. Any ideas?
I created my table as follow:
CREATE TABLE IF NOT EXISTS `test_sample` (
`ID` int(10) NOT NULL,
`name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;