Answered step by step
Verified Expert Solution
Link Copied!

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?

image text in transcribed
\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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

101 Database Exercises Text Workbook

Authors: McGraw-Hill

2nd Edition

0028007484, 978-0028007489

More Books

Students also viewed these Databases questions

Question

6. Describe why communication is vital to everyone

Answered: 1 week ago