简体   繁体   中英

Python requests.post timeing out on localhost

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?

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM