Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

pass post request using url generated by flask

I am using a flask tutorial that I found here…

https://andrewgriffithsonline.com/blog/180412-deploy-flask-api-any-serverless-cloud-platform/

In the "Test the App" section, there is a "http-prompt" command used. I do not want to use that. Instead I will like to use python requests module.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

That’s great! Using the requests library is a common and powerful way to interact with HTTP services in Python. Here’s an example of how you could use it to test your Flask app:

import requests
response = requests.get('http://localhost:5000/predict', json={'input': 'example input'})
print(response.status_code)
print(response.json())

This code will send a GET request to the /predict endpoint of your Flask app, passing a JSON payload with the key input and the value example input. The response from the server will be stored in the response variable, and you can access the status code and response content using the status_code and json() attributes, respectively. Note that you’ll need to change ‘http://localhost:5000/predict’ to the appropriate URL for your Flask app. If your app is running on a different host or port, you’ll need to update the URL accordingly.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading