[mod_python] Re: invalid literal for float solved addendum

tpc at csua.berkeley.edu tpc at csua.berkeley.edu
Fri Oct 31 09:11:57 EST 2003


hi Andy, I also do not see how this error could be raised.  I tested the
statement from IDLE shell as well as the other frameworks I mentioned
below.  I also reviewed the table creation statements to see if there was
something re MySQL data types I was missing:

<code>
        sql = """CREATE TABLE URLs (
              id INT AUTO_INCREMENT PRIMARY KEY NOT NULL,
              url VARCHAR(255) UNIQUE KEY NOT NULL,
              title VARCHAR(255)
              ) TYPE = InnoDB;"""

                sql = """CREATE TEMPORARY TABLE URLs_WITH_MATCHES (
                      url_id INT NOT NULL,
                      ) TYPE = InnoDB;"""
</code>

As you can see I am selecting two fields, url and title, from URLs where
URLs.id = URLs_WITH_MATCHES.url_id, both are type INT.

On Fri, 31 Oct 2003, Andy Dustman wrote:

> Sorry to have to ask this, but are you sure that's the SQL that
> generates the error? I don't see any way for that error to be raised.
>
> On Mon, 2003-10-27 at 17:14, tpc at csua.berkeley.edu wrote:
> > hi Grisha and Andy, after consulting with my coworker I believe there is a
> > bug in how MySQLdb interacts with mod_python that you should know of.  He
> > suggested I try out the same script that was giving me problems  with
> > Python CGI, and it works just fine.  The only difference is the values in
> > the tuple get switched around, so the tuple that is returned is (title,
> > URL) but no more invalid literal for float, int or long errors.  The
> > critical piece of code in question involves an implementation in Python
> > of a MySQL SELECT statement of two fields from one table joined to another
> > table that works just fine from the command line, in MySQL shell, and in
> > Python CGI:
> >
> > 	sql = """SELECT title, url FROM URLs, URLs_WITH_MATCHES WHERE
> > URLs.id = URLs_WITH_MATCHES.url_id;"""
> > 	cursor.execute(sql)
> >
> > gives me:
> >
> > <paste>
> > Mod_python error: "PythonHandler mod_python.publisher"
> >
> > Traceback (most recent call last):
> >
> >   File "/usr/lib/python2.2/site-packages/mod_python/apache.py", line 335,
> > in HandlerDispatch
> >     result = object(req)
> >
> >   File "/usr/lib/python2.2/site-packages/mod_python/publisher.py", line
> > 149, in handler
> >     module = apache.import_module(module_name, req.get_config(), [path])
> >
> >   File "/usr/lib/python2.2/site-packages/mod_python/apache.py", line 502,
> > in import_module
> >     module = imp.load_module(mname, f, p, d)
> >
> >   File "/var/www/html/python/temp-invalidtest.py", line 51, in ?
> >     search(terms)
> >
> >   File "/var/www/html/python/temp-invalidtest.py", line 47, in search
> >     results = getMP3SearchResults(terms)
> >
> >   File "/var/www/html/python/temp-invalidtest.py", line 15, in
> > getMP3SearchResults
> >     results = getMatchingURLs(cursor)
> >
> >   File "/var/www/html/python/temp-invalidtest.py", line 42, in
> > getMatchingURLs
> >     cursor.execute(sql)
> >
> >   File "/usr/lib/python2.2/site-packages/MySQLdb/cursors.py", line 95, in
> > execute
> >     return self._execute(query, args)
> >
> >   File "/usr/lib/python2.2/site-packages/MySQLdb/cursors.py", line 114, in
> > _execute
> >     self.errorhandler(self, exc, value)
> >
> >   File "/usr/lib/python2.2/site-packages/MySQLdb/connections.py", line 33,
> > in defaulterrorhandler
> >     raise errorclass, errorvalue
> >
> > ValueError: invalid literal for float(): <insert any mp3 title here>
> > </paste>
> --
> Andy Dustman         PGP: 0x930B8AB6
>     @       .net     http://dustman.net/andy
> Freedom isn't free. It's sold to the highest bidder.
>



More information about the Mod_python mailing list