Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started