Here is the python script
@app.route("/delete", methods=['POST'])
def delete_record():
mydb = con.connect(host="localhost", user="root", password="password", database="mysql_python")
cursor = mydb.cursor()
first_name = request.json['firstname']
query = "delete from user_accounts where First_Name = %s"
try:
cursor.execute(query, first_name)
mydb.commit()
mydb.close()
return "success"
except Exception as e:
return e
Here is json script passing from postman
{
"firstname":"Vikrant"
}
i am new to postman, trying to test the api through http://127.0.0.1:5000/delete using POST method. Not getting what i am doing wrong.
Here is full error
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:5000
Press CTRL+C to quit
[2022-08-21 11:43:41,281] ERROR in app: Exception on /delete [POST]
Traceback (most recent call last):
File "C:\Users\abhi\PycharmProjects\api\venv\lib\site-packages\flask\app.py", line 2525, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\abhi\PycharmProjects\api\venv\lib\site-packages\flask\app.py", line 1823, in full_dispatch_request
return self.finalize_request(rv)
File "C:\Users\abhi\PycharmProjects\api\venv\lib\site-packages\flask\app.py", line 1842, in finalize_request
response = self.make_response(rv)
File "C:\Users\abhi\PycharmProjects\api\venv\lib\site-packages\flask\app.py", line 2170, in make_response
raise TypeError(
TypeError: The view function did not return a valid response. The return type must be a string, dict, list, tuple with headers or status, Response instance, or WSGI callable, but it was a ProgrammingError.
127.0.0.1 - - [21/Aug/2022 11:43:41] "POST /delete HTTP/1.1" 500 -
Error on postman
<!doctype html>
<html lang=en>
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or
there is an error in the application.</p>