Search code examples
pythonapiflaskpostmanpythonanywhere

Deploying test flask API in pythonanywhere


I'm trying to deploy example flask API app given in flask document in pythonanywhere.


from flask import Flask, request
from flask_restful import Resource, Api

app = Flask(__name__)
api = Api(app)


todos = {}

class TodoSimple(Resource):
    def get(self, todo_id):
        return {todo_id: todos[todo_id]}

    def put(self, todo_id):
        todos[todo_id] = request.form['data']
        return {todo_id: todos[todo_id]}

api.add_resource(TodoSimple, '/<string:todo_id>')

if __name__ == '__main__':
    app.run()

When I was testing this app locally in pycharm, I executed app successfully by sending data using

curl http://localhost:5000/todo1 -d "data=Remember the milk" -X PUT

command in pycharm terminal.

The result I got is

{ "todo1": "Remember the milk" }

But when I tested the deployment using Postman the result I got is

The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again

Parameters used in Query params in Postman are: key:data value:"Remember the milk"

The result got when executed the app in locally is the correct result. What am I doing wrong?

PS: When using the pythonanywhere I used

http://www.mydomain.pythonanywhere.com

Solution

  • Data has to be send in 'Body' tab, not in 'Param' tab.