0

I'm doing the following request in curl:

curl --connect-timeout 2000 -d MY_JSON -H "Content-Type: application/json" -X POST MY_ADDRESS. 

After 20 minutes the server sends it's response and that works perfectly. But when I tried in python, it didn't work with the following code:

import requests
data=MY_JSON
requests.post(MY_ADDRESS, json=data, headers={'Content-Type' : 'application/json'}) 

I can see in the logs of the server that it sent a response but it doesn't look like the client is aware of that

I tried with different timeout and tried to add verify=False, tried to add another header, Accept, but it still didn't work

Requests did work when the response was under 10 minutes or so

AKX
  • 152,115
  • 15
  • 115
  • 172
  • If you have control over the server can you arrange for a response to be returned in a more timely fashion in order to try to eliminate timing issues? – DarkKnight Feb 13 '23 at 06:42
  • If you wrote the server, why not use websocket? – Wakeme UpNow Feb 13 '23 at 06:53
  • It doesn't look like you are actually capturing the response, unless it's not a whole code? You can try to print/log the response on the client side, add `raise_for_status` to see if some network error doesn't occur. – Gameplay Feb 13 '23 at 07:00
  • @Pingu, I'm not sure that I understand. What do you want me to try? – Ohad Kaiser Feb 13 '23 at 07:11
  • @WakemeUpNow I'm not sure how to use them, the server side is a simple flask server in python – Ohad Kaiser Feb 13 '23 at 07:12
  • @Gameplay the client doesn't get any response. Unless I add timeout to the request it is stuck. And this the whole code – Ohad Kaiser Feb 13 '23 at 07:13
  • Try https://stackoverflow.com/questions/48160130/using-flask-socketio-and-the-socketio-client. `20` minutes is a long time, by that point you should either optimize your code (response faster), or change architecture. Websocket is one solution, but another is to use message broker (large setup overhead), or lastly use message polling – Wakeme UpNow Feb 13 '23 at 07:23
  • Message polling idea is the post request return an task_id, and client query to check if this task_id is done every set interval. If the task_id is ready, return a new link to get the response – Wakeme UpNow Feb 13 '23 at 07:24
  • @WakemeUpNow I believe that any of those solutions would work but they require a lot of work for a simple synchronous requests. I'm trying to understand why does a simple post request doesn't work, I don't want to over engineer the project. – Ohad Kaiser Feb 13 '23 at 09:01
  • Try [this](https://stackoverflow.com/questions/47076402/requests-not-responding-on-long-wait-from-other-ip-rather-than-localhost) then – Wakeme UpNow Feb 13 '23 at 11:44

0 Answers0