0

I'm having trouble getting the Python requests module to post to an endpoint on the same server.

The server is running flask, and the route I want to post to is /new_applet.

My code is below. It is inside a different flask route function, which could be an issue?

url = "http://0.0.0.0:5000/new_applet"
data = {
    "action": "add",
    "plugin": plugin,
    "version": version,
    "component": component
}

resp = requests.post(url, data=data)

However it hangs while trying to make the post request. Debugging shows that the request never reaches the flask route function.

The request works if I run the following command on the server:

curl --location --request POST '0.0.0.0:5000/new_applet' \
  --form 'action=add' \
  --form 'plugin=up_spotify' \
  --form 'version=0.1' \
  --form 'component=inputs'

Why doesn't the Python request work, when the curl request does?

XDGFX
  • 41
  • 2
  • 9

1 Answers1

0

I believe flask runs a single thread by default.

According to your explanation, if the request is made from flask then it blocks the thread waiting for a reply (same thread that is supposed to handle the request.post).

you could try to use multiple thread as explained here: Can I serve multiple clients using just Flask app.run() as standalone?

Cyril Jouve
  • 990
  • 5
  • 15
  • That might well be the case. I had a look at that link and tried adjusting the threading options but to no avail. I'm actually running `flask_socketio`, which in my case is using `eventlet`'s wsgi server. I looked into that but didn't have any luck. Likewise with trying to run `gunicorn` in front of everything. I think in this case I will have to try to access the function internally, rather than sending another http request. Thanks :) – XDGFX Aug 30 '20 at 15:28