我的 python 代码有问题,我想将其用于 REST API 服务器。
当前的问题是,当我知道该值存在时,我的数据库查询返回 null
具体路径的代码:
@app.route('/data/active_predicted/<int:ticketId>', methods=['GET'])
def search_db_tickId_act(ticketId):
cursor = db.cursor()
db_query = cursor.execute("select * from active_predicted where ticketId=" + str(ticketId))
json_output = json.dumps(dict(cursor.fetchall()))
cursor.close()
if not cursor.fetchall():
return "Nothing found \n SQL Query: " + "select * from active_predicted where ticketId=" + str(ticketId)
else:
return str(cursor.fetchall())
Run Code Online (Sandbox Code Playgroud)
当我访问此 URL 时,我会返回以下内容:
没有找到 SQL 查询: select * from active_predicted where TicketId=1324
当我插入这个 SQL 查询时,我得到了我想要的结果,1 行 2 列,但程序似乎无法找到该行?