tpc at csua.berkeley.edu
tpc at csua.berkeley.edu
Tue Oct 21 12:06:37 EST 2003
I have attached my code, although I must ask if it was a MySQL error why does my script work fine on the command line and in IDLE ? Also, the script seems to throw an error during a cursor.execute(sql) of a SELECT statement: <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 194, in handler result = apply(object, (), args) File "/var/www/html/python/temp-invalidtest.py", line 45, in search results = getMP3SearchResults(terms) File "/var/www/html/python/temp-invalidtest.py", line 14, in getMP3SearchResults results = getMatchingURLs(cursor) File "/var/www/html/python/temp-invalidtest.py", line 40, 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> <paste> #!/usr/bin/env python """Created to solve bug that outputs invalid literal for float, int, long. Simplifies main search script and assumes query will always be one word long """ import MySQLdb DB = 'test' def getMP3SearchResults(terms): conn = MySQLdb.Connection(db=DB) cursor = conn.cursor() createTemporaryTable(cursor) identifyMatchingURLs(terms, cursor) results = getMatchingURLs(cursor) cursor.close() conn.close() return results def createTemporaryTable(cursor): try: sql = """CREATE TEMPORARY TABLE URLs_WITH_MATCHES ( url_id INT NOT NULL, ) TYPE = InnoDB;""" cursor.execute(sql) except: print "Error in creating URLs_WITH_MATCHES table" def identifyMatchingURLs(terms, cursor): sql = """INSERT INTO URLs_WITH_MATCHES SELECT DISTINCT WORDS_X_URL.url_id FROM WORDS_X_URL INNER JOIN WORDS ON WORDS_X_URL.word_id = WORDS.id WHERE WORDS.word = '% s' """ % terms cursor.execute(sql) def getMatchingURLs(cursor): sql = """SELECT URLs.url, URLs.title FROM URLs_WITH_MATCHES, URLs WHERE URLs_WITH_MATCHES.url_id = URLs.id GROUP BY URLs_WITH_MATCHES.url_id""" cursor.execute(sql) results = cursor.fetchall() return results def search(terms): results = getMP3SearchResults(terms) return results </paste> On Tue, 21 Oct 2003, Michael C. Neel wrote: > There's nor really enough info here to see the cause, but it's a MySQLdb > error, not a mod_python error. Your doesn't show the SQL statement you > are trying to execute, but my guess is that the field in the MySQL table > is defined as a float and your trying to insert a string (the title). > Seeing a few lines of the python module in question would help though. > > Mike > > > -----Original Message----- > > From: tpc at csua.berkeley.edu [mailto:tpc at csua.berkeley.edu] > > Sent: Tuesday, October 21, 2003 2:13 PM > > To: mod_python at modpython.org > > Subject: [mod_python] invalid literal for float > > > > > > > > hello all, I am trying to index and search mp3s in my Apache document > > root. Whenever executing a database select statement that retrieves > > the URL and title (the filename minus the .mp3 extension) of > > mp3s whose > > filenames contain the words I type into a web form, I get a "invalid > > literal for float" error message. The same script works fine on the > > command line and in IDLE. The error messages vary, and I > > sometimes see > > "invalid literal for int" or "invalid literal for long" though now it > > seems I just get "invalid literal for float." Also the error seems to > > come and go, and sometimes I get the results I want. I have > > gotten this > > type of message before when playing around with Python and trying to > > convert, say, a string to int, but this has me scratching my head: > > > > 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 > > 194, in handler > > result = apply(object, (), args) > > > > File "/var/www/html/python/temp-invalidtest.py", line 45, in search > > results = getMP3SearchResults(terms) > > > > File "/var/www/html/python/temp-invalidtest.py", line 14, in > > getMP3SearchResults > > results = getMatchingURLs(cursor) > > > > File "/var/www/html/python/temp-invalidtest.py", line 40, 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> > > > > > > _______________________________________________ > > Mod_python mailing list > > Mod_python at modpython.org > > http://mailman.modpython.org/mailman/listinfo/mod_python > > >
|