Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3431138
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:17:21+00:00 2026-05-18T07:17:21+00:00

I have a bug that I don’t know how to fix or even reproduce:

  • 0

I have a bug that I don’t know how to fix or even reproduce:

query = "SELECT id, name  FROM names ORDER BY id"
results = database.execute(query)

where the class Database contains:

def execute(self, query):
    cursor = self.db.cursor()
    try:
        cursor.execute(query)
        return cursor.fetchall()
    except:
        import traceback
        traceback.print_exc(file=debugFile)
        return []

This is how I open the database connection:

self.db = MySQLdb.connect(
    host=mysqlHost,
    user=mysqlUser,
    passwd=mysqlPasswd,
    db=mysqlDB
)

This is the stacktrace of the error:

File "foo.py", line 169, in application results = config.db.execute(query)
File "Database.py", line 52, in execute
     return cursor.fetchall()
File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 340, in fetchall
     self._check_executed()
File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 70, in _check_executed
     self.errorhandler(self, ProgrammingError, "execute() first")
File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 35, in defaulterrorhandler
     raise errorclass, errorvalue
ProgrammingError: execute() first

Do you have any ideas of why this is happening and how can I fix it? I searched on the internet and I found out that the reason may be having 2 cursors, but I have only one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T07:17:22+00:00Added an answer on May 18, 2026 at 7:17 am

    try this in your traceback it’s for debugging:

    except ProgrammingError as ex:
        if cursor:
            print "\n".join(cursor.messages) 
            # You can show only the last error like this.
            # print cursor.messages[-1]
        else:
            print "\n".join(self.db.messages)
            # Same here you can also do.
            # print self.db.messages[-1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an emergent bug that I've got to track down tomorrow. I know
I have a problem that someone introduced a bug but I do not know
I have a Swing browser application with a bug that as I add/remove to/from
I have a bug in my code that made me think I don't fully
I currently have a tricky bug that occurs in a place where I don't
i have bug that i cannot find, i have Class Point with method who
We have this bug that only appears 30% of the time for the Release
I have an curious zombie bug that seems to have crept out of the
Hey I have a really annoying IE7 bug that I am trying to work
We have a bug in our application that does not occur every time and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.