这是我的 Flask API 代码
from flask import request
from flask_restful import Resource
from mysql.connector import Error
from flask_jwt_extended import jwt_required, get_jwt_identity
from mysql_connection import get_connection
class OrderListResource(Resource):
# 내 주문내역 조회 API
@jwt_required()
def get(self):
userId = get_jwt_identity()
offset = request.args.get('offset')
limit = request.args.get('limit')
# 기본값
if not offset:
offset = 0
if not limit:
limit = 20
try:
connection = get_connection()
# 주문한 시간이 늦은 순으로 정렬
query = '''
select *
from orders
where userId = %s
order by createdAt desc;
limit '''+offset+''', '''+limit+''';
'''
record = (userId, )
cursor = connection.cursor(dictionary=True, buffered=True)
cursor.execute(query, record)
result_list = cursor.fetchall()
for row in result_list:
row['reservTime'] = row['reservTime'].isoformat()
row['createdAt'] = row['createdAt'].isoformat()
cursor.close()
connection.close()
except Error as e:
print(e)
cursor.close()
connection.close()
return {'error' : str(e)}, 500
return {'result' : 'success',
'items' : result_list,
'count' : len(result_list)}, 200
我使用 AWS lambda 部署了它,并使用 Postman 进行了测试。 在本地状态下工作正常,但服务器出现“Internal Server Error”。 当地的 AWS lambda
因此我查看了 CloudWatch 日志并收到以下错误消息:
[ERROR] InternalError: Unread result found
奇怪的是,在我部署的所有 API 中,只有这个 API 给我带来了错误。 Other APIs work fine both 当地的 and on the server. 所以我不知道问题出在哪里。
我在cursor()中放入bufferd=True,这是搜索“发现未读结果”错误时的解决方案,但没有效果。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我解决了这个问题!原因是;在查询中使用了两次。这是一个简单的问题,但在本地状态下运行正常,所以我找不到原因。对不起。