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!
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With