Django broken pipe error

dr.roman.graf at gmail.com dr.roman.graf at gmail.com
Mon Jan 2 09:14:06 EST 2017


On Monday, December 12, 2016 at 6:38:39 PM UTC+1, justin walters wrote:
> On Mon, Dec 12, 2016 at 7:27 AM, roma <dr.roman.graf at gmail.com> wrote:
> 
> > Thanks Justin,
> >
> > I believe, the whole database story has no influence on the broken pipe
> > error. I've commented out the whole block and leave only return line:
> > return HttpResponse(res, content_type="text/plain; charset=utf-8")
> > The error is still present. And I have no influence on that.
> >
> > I call python from js client:
> >
> >     var newTrendReport = new App.TrendReport();
> >     newTrendReport.set('search_phrase', search_phrase);
> >     newTrendReport.set('time_from', time_from);
> >     newTrendReport.set('time_to', time_to);
> >     newTrendReport.set('time_scale', time_scale);
> >     newTrendReport.set('category', category);
> >     newTrendReport.startExport(
> >
> >         function(response){
> >             console.log("Successfully calculated trend report.");
> >                 App.trendPage = new App.TrendPageView();
> >                 App.trendPage.render(response);
> >         },
> >     );
> >
> > go throw:
> >
> >     App.TrendReport = Backbone.Model.extend({
> >         urlRoot: "/api/trend_reports/",
> >         defaults: {
> >             search_phrase: "",
> >             time_from: "",
> >             time_to: "",
> >             time_scale: "",
> >             category: ""
> >         },
> >
> >         startExportSuffix: "/export_report/",
> >
> >         startExport: function( successCallback, errorCallback ) {
> >             console.log("start trend calculation");
> >             var that = this;
> >             var ajaxUrl = this.startExportSuffix;
> >             var options = {
> >                 method: "POST",
> >                 data: this.attributes,
> >                 contentType: "application/json;charset=UTF-8",
> >                 dataType: "json",
> >
> >                 error: errorCallback,
> >                 success: successCallback
> >             };
> >             console.log("start trend export sync");
> >             App.ajax(ajaxUrl, options);
> >         }
> >
> >     });
> >
> > and come in export_report method.
> >
> > My urls.py:
> >
> >     url(r'^export_report', ensure_csrf_cookie(views.export_report),
> > name="export_report"),
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> 
> I'm not super familiar with the way backbone does http requests, but
> something seems off about the startExport function.
> It seems to me that you are sending a post request to "/export_report/"
> which is an endpoint that I'm guessing is nested
> in an include from "/api/trend_reports/". However, it looks like the error
> you're getting above says you aren't sending
> the request to "https://root.com/api/trend_reports/export_report/".
> Instead, you are sending the request to "https://root.com/export_report/" .
> Though, I'm also not sure that's the case because that would normally throw
> a 404.
> 
> I also noticed that you set content type to 'application/json' in your js,
> but the view function returns a 'text/plain' content type. Is
> There a reason for this?
> 
> The data key in your js http function is set to the attributes variable
> which, as far as I can tell, does not exist.
> 
> There's a lot going on here, but I think you can probably narrow it down to
> something in your backbone code or the way
> backbone handles http requests as the error you are getting is caused by
> the client prematurely closing the socket.
> It's possible backbone will stop reading the response since it isn't the
> same content-type as the request.

Thanks a lot Justin,

The problem was solved when I employed standard Framework methods for creation of new database object:

in JS:
var trendModel = new App.TrendModel();
    trendModel.set("phrase", search_phrase);
    trendModel.set("from_time", time_from);
    trendModel.set(...
    trendModel.save(...

in PY:
    def create(self, request):
...

I've also created extra template and additional View. PageView for some unclear reason didn't support creation of new object - this event just disappeared.

Regards,

Roman



More information about the Python-list mailing list