'Flask restful api with mysql backend crashes when more than 2 apis are called from angular app
We are working on a test project and really do not know Flask and Flask restful much. Our python is not good as well, the problem is, we have developed an API server in Flask restful with MYSQL as backend database, and we have a front-end application which calls these apis. The problem is when the front-end calls more than 2 apis at the same time, the backend crashes and throws error
raise errors.OperationalError("MySQL Connection not available.")
mysql.connector.errors.OperationalError: MySQL Connection not available.
, if we call these api one at a time, either from browser or from postman, these api works.
This is how we are using mycursor ( We tried creating different cursors for each query and closing them right after fetching results but that did't work as well )
from flask_restful import Resource
import json
import pandas as pd
from common.util import mydb, mycursor
class GetStudentCount(Resource):
def get(self):
# Available student count for sale
sql = "SELECT COUNT(1) AS studentCount FROM Student;"
mycursor.execute(sql)
student_count = mycursor.fetchall()
return {'count': student_count[0][0]}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|