简体   繁体   English

Bottle和MySQLdb中Int,Decimal或Datetime类型的执行不起作用

[英]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 在PythonAnywhere.com的Bottle中使用MySQLdb时遇到一个非常奇怪的错误

Whenever the execute contains columns of type int, decimal or datetime, the execute throws a 500 error. 每当执行包含int,decimal或datetime类型的列时,执行都会引发500错误。 For example, from a table Tools, manufacturer and sub_type are both varchars, so this block of code works perfectly: 例如,从表Tools中,Manufacturer和sub_type都是varchars,因此此代码块可以完美地工作:

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: 但是,请从该表中获取int类型的同一表,或从该表中获取int,十进制或日期时间类型的任何其他列:

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: 并且Bottle引发严重错误:

Error running WSGI application SystemError: returned a result with an error set 运行WSGI应用程序SystemError时出错:返回了带有错误集的结果

In MySQL bash, every query works perfectly. 在MySQL bash中,每个查询都能完美运行。 Put that same query (only int, decimal or datetime) in execute(), and it fails. 将相同的查询(仅int,十进制或datetime)放在execute()中,它将失败。

Has anyone had any similar experience? 有没有类似的经历?

Are you returning row as your WSGI response? 您是否要返回row作为WSGI响应? If so, that's the problem. 如果是这样,那就是问题所在。 According to the WSGI standard : 根据WSGI标准

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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