skip to Main Content

I have deployed a Django rest framework service with multiple APIs on my Ubuntu 20.04 server with Gunicorn, everything works fine, but PATCH requests from outside the server do not receive a response, although the application receives the request and fully processes it.
I have even tested it with Django runserver and the problem remains and has nothing to do with Gunicorn.
Steps to reproduce:

  1. On the server we create a new Django application:
ssh to_my@server
python3 -m pip install django
django-admin mytest
cd mytest
python3 manage.py runserver 0.0.0.0:9999
  1. On the server trying to send requests to the application:
ssh to_my@server
curl --request GET localhost:9999/ # this works fine and we can see the response
curl --request PATCH localhost:9999/ # this works fine too
  1. On another machine try these:
# on my local machine
curl --request GET IP:9999/ # this works fine
curl --request PATCH IP:9999/ # **** this will get a `curl: (56) Recv failure: Connection reset by peer` after some times

The response never arrives although in the console you can see that the request is fully received and Django has no problem:

Invalid HTTP_HOST header: '207.154.246.122:9999'. You may need to add '207.154.246.122' to ALLOWED_HOSTS.
Bad Request: /
[02/Nov/2021 11:18:25] "PATCH / HTTP/1.1" 400 62827

Please ignore the Exception it has nothing to do with our problem.
Note that this is a minimal deployment, I am serving via HTTP not HTTPS and the port is already open, I know I can use PUT instead of the PATCH method, and I am not using NGINX just forwarding it directly.
My question is: what is causing this behavior? is this the operating system? and how I can solve this problem and receive the response from my PATCH requests?

2

Answers


  1. Chosen as BEST ANSWER

    After some investigation, I have found that I am able to send the Patch request to the server and receive the response from another server, this means that my client network was blocking the response from the server, At that time I was using Irancell network, and if you have a similar problem this is a thing with your ISP and if it is necessary you have to contact them, at the end everything related to these technologies is working very well...
    But my question has upgraded to how is the ISP is able to decide and block the response to just the Patch method? maybe I will ask it in another question and add the link here later...


  2. I changed my response status from

    return Response(serializer.data, status=status.HTTP_204_NO_CONTENT)
    

    to

    return Response(serializer.data, status=status.HTTP_200_OK)
    

    and now it works

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search