0

I'm using python to read values from REST API and write to a MySQL table. One of the returned values is a JSON, which I want to store in the DB.

The value returned by the API has escaped quotes and looks something like:

{\"dashboard\":\"val\"}

When I use print, I see that the escape characters are replaced with the actual quotes (which is the desired outcome):

{"dashboard":"val"}

However, when I'm using the MySQLdb execute or executemany (with tokenised params) - the value written to the database has all the double quotes replaced with single quotes, making it a non-valid json:

{'dashboard':'val'}

How do I avoid that?

Aamit
  • 181
  • 4
  • 16

1 Answers1

0

You should change your library into mysql.connector or pymysql or etc , because MySQLdb has some problems you can not predict. Even though your parameters and base_sql are correct. I recommend mysql.connector, because it is MySQL official library. https://dev.mysql.com/downloads/connector/python/

KC.
  • 2,981
  • 2
  • 12
  • 22