Question: How do I create an API route with MySQL database using Python? So far I have, @app.get(/assumptions/{id}) def assumptions(id: int): cursor = conn.cursor() query =
How do I create an API route with MySQL database using Python?
So far I have,
@app.get("/assumptions/{id}")
def assumptions(id: int):
cursor = conn.cursor()
query = 'SELECT column1, column2, column3 FROM database.assumptions WHERE id = :id'
cursor.execute(query, {'id' : id})
result = cursor.fetchone()
cursor.close()
assump_response = models.ProjectionAssumptions(column1 = result['column1'],
column2 = result['column2'],
column3 = result['column3'])
return assump_response
But my API keeps returning Internal Server Error. Can you help me fix the problem?
\begin{tabular}{|r|r|r|r|} \hline id & column1 & column2 & column3 \\ \hline 1 & 1 & 50 & 10 \\ \hline 2 & 1.05 & 50 & 10 \\ \hline 3 & 0.95 & 50 & 10 \\ \hline \end{tabular}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
