'RemoteDisconnected Error when using requests.patch on Eve endpoint

I'm trying to track down a frustrating error with my Eve application. I am trying to update a record, but whenever I send the patch request, I am greeted with the following error:

 File "/home/undivided/.local/lib/python3.6/site-packages/requests/api.py", line 140, in patch
return request('patch', url, data=data, **kwargs)
 File "/home/undivided/.local/lib/python3.6/site-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/home/undivided/.local/lib/python3.6/site-packages/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/home/undivided/.local/lib/python3.6/site-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/home/undivided/.local/lib/python3.6/site-packages/requests/adapters.py", line 490, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))

The request is being made like this:

res = requests.patch(
    url,
    json=mydata,
    headers={
        "If-Match": _etag,
        "Authorization": 'Bearer {}'.format(eve_token)
    }
)

The strange thing is, that all other request types to the same instance, including a GET to the exact same record, return properly. There are no errors that I can see in the Eve logs either.

The only possible complicating factor I can think of is that the eve application is deployed on a kubernetes cluster, but, as I said, all of the GETs/POSTs I have tried work as expected.

EDIT:

To add a further complicating factor, when I exec into my pod and try the request there, it succeeds, so it seems the problem is related to Kubernetes? Do I need to do something to enable HTTP PATCH on Kubernetes?



Solution 1:[1]

I know this question is almost four years old, but if anyone stumbles upon this:

We had a very similar issue. PATCH requests from Python's requests to an application in our Kubernetes cluster failed with the Remote end closed connection without response message, while browser requests (and copying them to CURL and executing it from the CLI) worked fine.

Running the same Python script inside the cluster also worked fine (even from a different pod), so it seems like the issue is somewhere on the ingress (?) or at least not in the application.

After a bit of tinkering with the headers, we found out that the requests work if we remove the Accept-Encoding header from the python request by setting it to None:

head = {
  # ... other headers ...
  "Accept-Encoding": None,
}
r = requests.patch(url, json=payload, headers=head)

I'm not sure why this works, especially since CURL also works with the Accept-Encoding header.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alex