1

python MySQL pool is returning 'u' key in the array as like - [{u'data': u'{"no_comment":1,"total_reply":2}'}]

A required response should be like - [{"data": {"no_comment":1,"total_reply":2}}].

query - "select data from tbl_comment where id = 10"

reference code -

def query(_db_config, _sql, _args):
   conn = get_pool_connection(_db_config)
   if not isinstance(conn, PooledMySQLConnection):
      cursor = conn.cursor(MySQLdb.cursors.DictCursor)
   else:
      cursor = conn.cursor(dictionary=True)
   result = ()
   try:
      cursor.execute(_sql, _args)
      result = cursor.fetchall()
   except:
     pass
     rootLogger.error("query exception sql is %s ,_args is %s,stacks is %s", _sql, _args, get_caller_info_total())
     rootLogger.exception("message")
   finally:
     cursor.close()
     conn.close()
   return result
rohit-s
  • 69
  • 4
  • A similar question already exists: https://stackoverflow.com/questions/2081640/what-exactly-do-u-and-r-string-flags-do-and-what-are-raw-string-literals – Roberto Bellarosa Dec 04 '19 at 13:07

2 Answers2

0

you can try like this:

SELECT column1, CAST(CONVERT(column2 USING utf8) AS binary)
FROM my_table
WHERE my_condition;
rajvi
  • 150
  • 11
0

I used the encode function for fetched data. Unicode to ASCII converted for the solution.

rohit-s
  • 69
  • 4