RE: Inserting HTML page to TEXT fails... syntax error?! (Python MySQLdb)

2003-07-17 Thread Nick Arnett
> -Original Message-
> From: Paul DuBois [mailto:[EMAIL PROTECTED]
> Sent: Thursday, July 17, 2003 9:38 PM
> To: Nick Arnett; [EMAIL PROTECTED]

Well, Paul, just knowing you were on the job inspired me and I finally
realized the dumb thing I'd done.  The list I'm iterating, urls, comes from
a single-column MySQL results list, so it's a list of tuples (url,), not
strings.  That's why I open url[0], rather than just url in the first line
inside the loop.  I was smart enough to do that, but not smart enough to
remember to use url[0], rather than url, in the INSERT statement.  So I was
trying to insert a tuple, not a string, and thus MySQL barfed.

> >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,))


> - 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?

By the way, what helped me figure this out was switching the column names
and values, which changed the string in the error message to "))", rather
than the start of the HTML doc.  That's when I realized the problem was
something about url, not the HTML.

This one has bitten me before, but it's been a long time...

Nick


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Inserting HTML page to TEXT fails... syntax error?! (Python MySQLdb)

2003-07-17 Thread Paul DuBois
At 20:49 -0700 7/17/03, Nick Arnett wrote:
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]


Inserting HTML page to TEXT fails... syntax error?! (Python MySQLdb)

2003-07-17 Thread Nick Arnett
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.

Nick

--
Nick Arnett
Phone/fax: (408) 904-7198
[EMAIL PROTECTED]



-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]