Home > database >  Flask Invalid Status Argument when requesting from API
Flask Invalid Status Argument when requesting from API

Time:01-05

I'm having an issue where when I try to GET all restaurants through my api route.

Using http://localhost:5000/restaurant/

@restaurant.route('/', methods=['GET'])
def get_all_restaurants():
    """Get all restaurants"""

    try:
        restaurants = list(restaurants_collection.find())
    except Exception as e:
        return make_response({'message': f'something went wrong {e}'}, 400)

    return {'status': 200} , jsonify(restaurants)

I'm running into this error.

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2525, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1823, in full_dispatch_request
    return self.finalize_request(rv)
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1842, in finalize_request
    response = self.make_response(rv)
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2184, in make_response
    rv.status_code = status
  File "/usr/local/lib/python3.8/site-packages/werkzeug/sansio/response.py", line 151, in status_code
    self.status = code  # type: ignore
  File "/usr/local/lib/python3.8/site-packages/werkzeug/sansio/response.py", line 161, in status
    raise TypeError("Invalid status argument")
TypeError: Invalid status argument
 - - [04/Jan/2023 14:06:47] "GET /restaurant/ HTTP/1.1" 500 -

The part I don't understand is that if there is some sort of error wouldn't my Exception be getting it and returning it to me? I'm currently running this application using docker.

I've tried finding guidance for this online but couldn't find anything regarding this error. Let me know if there is anything else I can provide you guys with.

CodePudding user response:

The error could be in return. You don't need status if it is 200 return jsonify(...). If you want to return status , it should be return jsonify(...), 200

  • Related