3

I am trying to use flask_restful to create an API using Python. I have the following code:

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

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

class Example(Resource):

    def get(self):
        parser = reqparse.RequestParser()
        parser.add_argument('some_arg')
        args = parser.parse_args()
        return {"Param Entered": args['some_arg']}

api.add_resource(Example, '/')

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

When running the GET request in Postman:

GET <my_url>/?some_arg=<some_text>

I get the error: "message": "The browser (or proxy) sent a request that this server could not understand."

Could someone please explain why this error shows and how I can add arguments properly using parse_args() for flask restful? Thank you!

1 Answer 1

5

A bit late to the party, but I also got the issue and managed to solve it by chaning parser.add_argument('some_arg') to parser.add_argument('some_arg', location='args').

Without the location parameter, it was working fine on my Windows machine, but not on my Linux one (EC2 instance).

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you this worked for me too on MacOs Monterey 12.5
before it was working fine without location='args' on Linux, but now maybe they changed something in the flask library

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.