You have created a Flask API using Flask RESTX. I’ve run it locally in a container and it’s working as expected. My endpoint is waiting for POST requests:
class MyAPIEndpoint(Resource): Def post (self): return hello
It’s very simple. When I run my Flask app on Google Cloud Run (it doesn’t matter if I use gunicorn or unsafe app.run() directly), I get a “405 Method Not Allowed” message. I can see in the console that the request was redirected to a GET request, which I didn’t allow in the endpoint above.
POST 308 1.04KB 5ms PostmanRuntime/7.31.0
/myendpoint POST 302 0B 0ms PostmanRuntime/7.31.0 /myendpoint GET 405 735B 3ms PostmanRuntime/7.31.0 /myendpoint
As you can see, the request has been redirected. I don’t understand why you are doing this. I haven’t changed the docker image I’m using locally.
A Google Cloud Run Service deployment has no non-default configuration.
Interestingly, the login and admin pages (built with Flask Admin) work fine.
Does anyone know what’s going on?
Edit: I think Flask itself triggers the 308 redirect. This is to log the 308 to the infolog channel. Then there are other log messages like the one above. I lost all my post data in the redirect as I can also see in the logs that the body was dropped.
It was a Google Cloud Run problem – I had to create an API gateway to enable API functionality.
Answered By – Standard
Answer Checked By – Laura B. (Easybugfix Admin)