Escape string Python for MySQL


Question

I use Python and MySQLdb to download web pages and store them into database. The problem I have is that I can't save complicated strings in the database because they are not properly escaped.

Is there a function in Python that I can use to escape a string for MySQL? I tried with ''' (triple simple quotes) and """, but it didn't work. I know that PHP has mysql_escape_string(), is something similar in Python?

Thanks.

1
62
8/12/2015 5:51:27 PM

conn.escape_string()

See MySQL C API function mapping: http://mysql-python.sourceforge.net/MySQLdb.html

83
9/1/2010 10:29:58 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon