search

Home  >  Q&A  >  body text

I think this is a Python MySQL bug but I can't understand the situation. Internal error: Unread results found

This is my Flask API code

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

I deployed it using AWS lambda and tested it using Postman. It works fine in local state, but the server gets "Internal Server Error". Local AWS lambda

So I looked at the CloudWatch logs and got the following error message:

[ERROR] InternalError: Unread result found

The weird thing is that out of all the APIs I deployed, this is the only one that gave me the error. Other APIs work fine both local and on the server. So I don't know where the problem is.

I put bufferd=True in cursor(), which is the solution when searching for "unread results found" error, but it has no effect.

P粉193307465P粉193307465451 days ago402

reply all(1)I'll reply

  • P粉982054449

    P粉9820544492023-09-11 13:33:08

    I solved this problem! The reason is; is used twice in the query. This is a simple problem but works fine locally so I can't find the cause. sorry.

    reply
    0
  • Cancelreply