简体   繁体   中英

Execution of Int, Decimal or Datetime Types in Bottle and MySQLdb Not Working

I'm getting a very strange error while using MySQLdb in Bottle on PythonAnywhere.com

Whenever the execute contains columns of type int, decimal or datetime, the execute throws a 500 error. For example, from a table Tools, manufacturer and sub_type are both varchars, so this block of code works perfectly:

reservation_id = request.forms.get("reservation_id")
db = MySQLdb.connect("...")
c = db.cursor()
c.execute("""SELECT manufacturer, sub_type FROM Tool""")
row = c.fetchone()
return row

But ask for the tool_id from that same table, which is of int type, or any other column of int, decimal or datetime type from that table:

reservation_id = request.forms.get("reservation_id")
db = MySQLdb.connect("...")
c = db.cursor()
c.execute("""SELECT tool_id FROM Tool""")
row = c.fetchone()
return row

And Bottle throws a critical error:

Error running WSGI application SystemError: returned a result with an error set

In MySQL bash, every query works perfectly. Put that same query (only int, decimal or datetime) in execute(), and it fails.

Has anyone had any similar experience?

Are you returning row as your WSGI response? If so, that's the problem. According to the WSGI standard :

When called by the server, the application object must return an iterable yielding zero or more strings.

To illustrate this, try converting your row to a string first and confirm that that helps. Eg,

...  # your existing code
return [str(col) for col in row]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM