Broken Pipe on $.ajax request

The code in CustomScript (ajax POST request - GET works fine!):

frappe.ui.form.on(“ToDo”, “description”, function (frm) {

             url: encodeURI("/api/resource/Customer"), 
             type: "post", 
             beforeSend: function(xhr) {
                xhr.setRequestHeader("X-Frappe-CSRF-Token", frappe.csrf_token);
                xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
             data: {}

//# sourceURL=debug_me.js

Need tip how to debug this kind of error:

Traceback (most recent call last):
File “/home/marcin/frappe-bench/apps/frappe/frappe/”, line 15, in call
return super(StaticDataMiddleware, self).call(environ, start_response)
File “/home/marcin/frappe-bench/env/lib/python2.7/site-packages/werkzeug/”, line 599, in call
return, start_response)
File “/home/marcin/frappe-bench/env/lib/python2.7/site-packages/werkzeug/”, line 599, in call
return, start_response)
File “/home/marcin/frappe-bench/env/lib/python2.7/site-packages/werkzeug/”, line 228, in application
return ClosingIterator(app(environ, start_response), self.cleanup)
File “/home/marcin/frappe-bench/env/lib/python2.7/site-packages/werkzeug/”, line 291, in application
return f(*args[:-2] + (request,))(*args[-2:])
File “/home/marcin/frappe-bench/apps/frappe/frappe/”, line 80, in application
response = handle_exception(e)
File “/home/marcin/frappe-bench/apps/frappe/frappe/”, line 135, in handle_exception
response = frappe.utils.response.report_error(http_status_code)
File “/home/marcin/frappe-bench/apps/frappe/frappe/utils/”, line 24, in report_error
File “/home/marcin/frappe-bench/apps/frappe/frappe/”, line 229, in errprint
print cstr(msg)
IOError: [Errno 32] Broken pipe

This only happens on POST requests, the data provided does not seem to have any impact on this request.

For inserting records you seem to use GET instead of POST (not talking about CRUD, but form itself). Is it relevant to the case?

This usually happens when the request is taking too long.

When the request takes too long, it is terminated, either by Nginx or by the client itself.

May e this will help you debug.

try method instead of type

below is the snippet which works for my use case

             url: encodeURIComponent("/api/resource/Customer Plant Variables/" +,
             method: "PUT",
             data: {data: JSON.stringify({enabled: elem.checked?1:0})}

Yeah - it seems error reporting in Frappe is not always accurate - will fix the documentation for proper Ajax examples.
@BhupeshGupta - thank you for your reply, basically in it waits for “data” key in form_dict. It means you have to go for

data: { data: JSON.stringify( dictOfParams) }

as you wrote.

Thx anyway and topic to be closed.