My hair... I am ready to tear it out. I've been working with Python and the MySQLdb module for a long time, thought I couldn't get snagged by anything, but today I just can't seem to persuade the blasted thing to let me stick an HTML document (a string) into a TEXT column. I'm getting SQL syntax errors, as though the document isn't properly escaped, even though I'm using substitution so that MySQLdb should be taking care of that. I'm wondering if I'm missing something terribly obvious, because this is dead-simple code. Here's the relevant bit and a couple of surrounding lines.
for url in urls: doc = urllib.urlopen(url[0]).read() dbh.execute("INSERT INTO rss_article (body,url) VALUES (%s, %s)",(doc, url)) dbh.execute("UPDATE rss_item SET cached = '1' WHERE url = %s",(url,))
It's retrieving the document just fine, resulting in a big ol' string (it really is a string, I checked), but that string just won't go into the database. rss_article is a TEXT column in a MyISAM table. I get an SQL syntax error and MySQL tells me to check the syntax with a snippet from right near the beginning of the HTML, where it has lots of (annoying, I suppose) backslashes, quotes and other stuff that is a pain to encode properly by hand.
Any help will be most gratefully accepted. My hair will thank you, too.
- Have you tried this with *short* HTML documents? What happens? This would help you determine whether it's a length-of-data issue. - Let's see an actual error message (at least the first part), and the corresponding text of the document. - What shows up in the server's query log?
Nick
-- Nick Arnett Phone/fax: (408) 904-7198 [EMAIL PROTECTED]
-- Paul DuBois, Senior Technical Writer Madison, Wisconsin, USA MySQL AB, www.mysql.com
Are you MySQL certified? http://www.mysql.com/certification/
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]