문제

I'm running the Django 1.2 development server and I get these Broken Pipe error messages whenever I load a page from it with Chrome or Safari. My co-worker is getting the error as well when he loads a page from his dev server. We don't have these errors when using Opera or Firefox.

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/servers/basehttp.py", line 281, in run self.finish_response()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/servers/basehttp.py", line 321, in finish_response self.write(data)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/servers/basehttp.py", line 417, in write self._write(data)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/socket.py", line 300, in write self.flush()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/socket.py", line 286, in flush self._sock.sendall(buffer)
error: [Errno 32] Broken pipe

Can anyone help me out? I'm going crazy over this!

도움이 되었습니까?

해결책

This is not a Django issue. Your browser is most likely doing something erroneous.

This is common error which happens whenever your browser closes the connection while the dev server is still busy sending data.

Check this Django ticket for more info.

다른 팁

I just recently ran into this issue with the django v1.1.1 dev server and Chrome 7.0.517.44.

The "fix" that I've discovered is always doing a hard refresh (hold Shift and click the reload button in Chrome) on the page after the initial load, which causes Chrome to ignore it's cache for any resources requested by the refresh.

As such, this leads me to believe it's an issue with Chrome's notorious tendency to cache everything it possibly can; even when it shouldn't. My guess is that Chrome is making a resource request and then immediately dropping the connection for said resource once it realizes it has the resource cached.

This would almost be a bearable workaround, except any AJAX requests will still cause problems.

This can be due an error in the javascript function dispatching the ajax call.

For example, the function may be triggered by a click event on a link, and if the default action of link is not prevented, you will get a secondary request right away and the browser will close the previous connection without waiting for the response to finish. I had the same problem when I forgot to add return false to the event handler.

The same symptom can occur if the event handler triggering ajax throws an exception.

Debug carefully the function making the ajax request and the return value of that function.

A broken pipe happens when the browser closes the connection with the server. This problem happened with me before on ajax post request associated with <a href="... because I forgot to add e.preventDefault() in the click handler function. So what happened is that the browser send the post request and close the connection and send another get request. So you will see like the post request was canceled by the browser.

I had a possibly related problem.

While using Safari and Chrome on Windows, on my local machine on my django runserver, some views were randomly not returning a response to ajax POST requests.

The solution was this:

The data I was passing in to the view via POST was just one key/val pair: "action=remove". Now, I wasn't actually using this data in my view. Once I assigned the data to a var in my view, (i.e. foo = request.POST['action']), the view would return a response to ajax requests every time.

Absolutely crazy!

In the case that this happens with a JavaScript client, a solution could be the following. You have to add preventDefault and return false at beginning and at the end of your event handler like:

$('#btn_analyze').click(function(e) {
    e.preventDefault()
    $.post('/api/v1/analyzer/',
        data,
        "json").done(function(response) {
        //...
    }).fail(function() {
        Logger.error(" Error ")
    })

    return false
}) // analyze click
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top