Menu

cursor.execute dies silently, w/mod-pytho

Help
2004-03-17
2012-09-19
  • Eddie Parker

    Eddie Parker - 2004-03-17

    Hello!

    I'm using mysql-python, and I'm trying to use it from inside of mod-python (apache module) code, and it simply dies on the execute - no errors are issued, but print debugging shows that it dies before the call to execute.

    Is there anything I have to watch out for? There's nothing strange about what I'm doing, so I'm not sure what's goin on.. Let me know if I need more information - I'd appreciate any help people can give me! :)

    Cheers

     
    • Greg Fortune

      Greg Fortune - 2004-03-17

      Dies in what fashion?

      Are any tracebacks generated?  If so, what are they?

      Can you include a snippet of code?

      Have you got it working outside of mod_python?

       
      • Eddie Parker

        Eddie Parker - 2004-03-17

        Thanks for your response Greg, here's the answers:

        a) Dies in what fashion?

        All I can tell is that all code after a cursor.execute([query]) doesn't get executed. I'm using 'req.write()' to debug where I'm getting to, and right before the cursor.execute(), everything's fine, and immediately afterwards, nothing happens.

        The only testing I've accomplished is that *not* using a table for getting my data (i.e., cursor.execute("SELECT 2+2")) works. The moment I select stuff from my DB, however, it fails.

        b) Can you include a snippet of code?

        Well, I guess my question is - what do I give? The snippet of code looks something like this:

        def handle_clientreply(req, fields):
            db = MySQLdb.connect(host="myhost", user="myuser", passwd="mypasswd", db="mydb")
            cursor = db.cursor()
            sql_query = "SELECT foo from mytable";
            req.write("Everything works up to here")
            cursor.execute(sql_query)
            req.write("This will not get printed. Everything from here on in, might as well not be written.")

        It's paraphrased, but that's what I can boil it down to.

        c) Have you got it working outside of mod_python?

        Yes. Even the same script (I'm using the same script to store e-mail generation and the subsequent form handling) works, so long as I run it from the command line.

        I'm totally lost. :(. If I need to give any more information, please let me know - but I'm dying for some help!

        Are there any other debugging techniques I should know about? It's hard to do adequate printf debugging, since I can't pass down 'req' to all the internals.. Anyone have an idea how to do this? Or have a fix for me? :) Thanks!

         
        • Eddie Parker

          Eddie Parker - 2004-03-17

          I'm reading up a bit, and finding that some users have found weird issues with mod-python and mysql-python.. They sound similar, and they seem to be work-aroundable by changing SQL statements.

          I profess that my mastery of SQL is somewhat lack luster, so I'll post my SQL query, in the hopes that maybe someone can point out my folly:

              SELECT i._title AS TITLE,
                         i.id AS ID
                 FROM _issue AS i
          INNER JOIN _status AS S
                     ON i._status=s.id
                WHERE i._creator=3
                    AND s._name != 'Closed'
                    AND IF(CAST(i._checkup as signed) = 0, UTC_TIMESTAMP() > DATE_ADD(STR_TO_DATE(i._creation, "%Y%m%d%H%i%s"), INTERVAL 1 DAY), UTC_TIMESTAMP() > DATE_ADD(STR_TO_DATE(i._creation, "%Y%m%d%H%i%s"), INTERVAL CAST(i._checkup as SIGNED) DAY))

          If I'm doing anything wrong, I apologize for offending your sensibilities - but please help me out so I can learn from this painful endeavor. :)

           
          • Greg Fortune

            Greg Fortune - 2004-03-18

            I don't see anything blatently wrong, but I can't see your db schema either.  One thing that I've never seen used is the CAST function and I don't see it in the docs for 4.0.  You might check that.

            Best bet is to find out what the traceback says and go from there.

             
        • Greg Fortune

          Greg Fortune - 2004-03-18

          Sounds like you're getting a traceback in the execute call.  That can happen for a variety of reasons, but most likely because your query is malformed.  Not really much help if you don't know the error message though :)

          Try the following.. Note that one line is wrapping...  Also note that you probably want to replace
            print "foo"
          with
            req.write("foo")

          try:
          cursor.execute(query_string, params)
          except (MySQLdb.ProgrammingError, MySQLdb.OperationalError), error:
          print str(error[1])
          except StandardError, error:
          import traceback
          print error.__class__
          print "-- " + str(error.__class__) + " during query --"
          print traceback.print_exc()
          print "-----------------------------------------------------"
          print 'query:  ' + str(query_string)
          print 'params: ' + str(params)

          results = list(self.cursor.fetchall())

          If that gives you a traceback, post it back to the list.  You might also be able to find the tracebacks logged through mod_python..  Maybe in the Apache logs???  From what I read in the mod_python docs, that appears to be the case so pull open the apache logs and see if you find any tracebacks in there after executing a query.

           
    • Aarre

      Aarre - 2004-09-08

      I am having exactly the same problem.
      --------
      My system configuration:
          Debian Linux 2.4.26-1-k6 (unstable)
          Python 2.3.4
          mysql  Ver 12.22 Distrib 4.0.20, for pc-linux-gnu (i386)
          Apache/1.3.31 (Debian GNU/Linux)
          mod_python 2.7.10
      --------
      My code:

          cursor = db.cursor()
          sql = "SELECT * FROM note ORDER BY id LIMIT 100"
          req.write(sql+"<br>\n")
          try:
              req.write("trying...<br>\n")
              cursor.execute(sql)
              req.write("tried...<br>\n")
          except (MySQLdb.ProgrammingError, MySQLdb.OperationalError), error:
              req.write("exception...\n")
              msg = "Error %d: %s" % (error.args[0], error.args[1])
          req.write(msg)
          req.write(str(error[1]))
          except StandardError, error:
              req.write("exception...\n")
          import traceback
          req.write(error.__class__)
          req.write("-- " + str(error.__class__) + " during query --")
          req.write(traceback.print_exc())
          req.write("-----------------------------------------------------")
          req.write('query: ' + str(query_string))
          req.write('params: ' + str(params))
      ----------------------
      Results:
        This code worked at one time, but recently broke during a Debian dselect update (various software changed). It still works just fine from the Python interpreter command line. When executed through the browser, the SQL statement and the "Trying..." line are written to the output, but the "Tried..." line is not. No traceback or other exception information is written to the output.
          /var/log/apache/error.log contains the following lines:
          [Tue Sep  7 18:15:35 2004] [notice] mod_python: (Re)importing linki from None
      [Tue Sep  7 18:15:36 2004] [notice] child pid 21564 exit signal Segmentation fault (11)
      -----------------------
      Following the suggestion at
         http://www.modpython.org/FAQ/faqw.py?req=all#2.13
      I disabled mod_php4, and that fixed the problem. However, I cannot leave mod_php4 disabled. Is there any way that MySQLdb can be modified to prevent this problem?

       
      • Andy Dustman

        Andy Dustman - 2004-09-08

        Wow, every version except for what version of MySQL-python you are using.

        Give 1.1.3 a try. I am confident that this is the best available version for Python-2.3.

         
        • Aarre

          Aarre - 2004-09-08

          Ooops. I'm not sure how to find the exact version. Debian's version number for package python-mysqldb is 1.0.0-1, but the latest version number referenced in /usr/share/doc/python2.3-mysqldb/Changelog is 0.9.3a2

          I will try the version you recommend, thanks.

           
        • Aarre

          Aarre - 2004-09-08

          Yes, 1.1.3 with 'export mysqlclient="mysqlclient_r"' works! Thank you!!!

           

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.