姜戈 + WebKit = 管道破损

发布于 2024-09-02 07:15:39 字数 968 浏览 5 评论 0原文

我正在运行 Django 1.2 开发服务器,每当我使用 Chrome 或 Safari 加载页面时,都会收到这些 Broken Pipe 错误消息。我的同事从他的开发服务器加载页面时也遇到了错误。使用 Opera 或 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

有人可以帮我吗?我快要疯了!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

苏璃陌 2024-09-09 07:15:39

这不是 Django 问题。您的浏览器很可能执行了错误的操作。

这是常见的错误
每当您的浏览器关闭时
开发服务器处于连接状态时
仍在忙于发送数据。

查看此 Django 票证了解更多信息。

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.

草莓味的萝莉 2024-09-09 07:15:39

我最近刚刚在 django v1.1.1 开发服务器和 Chrome 7.0.517.44 上遇到了这个问题。

我发现的“修复”总是在初始加载后在页面上进行硬刷新(按住 Shift 键并单击 Chrome 中的重新加载按钮),这会导致 Chrome 忽略刷新请求的任何资源的缓存。

因此,这让我相信这是 Chrome 臭名昭著的缓存一切可能的倾向的问题;即使不应该。我的猜测是,Chrome 正在发出资源请求,然后在意识到已缓存该资源后立即断开该资源的连接。

这几乎是一个可以忍受的解决方法,除非任何 AJAX 请求仍然会导致问题。

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.

梦里梦着梦中梦 2024-09-09 07:15:39

这可能是由于调度 ajax 调用的 javascript 函数中出现错误所致。

例如,该功能可能是由链接上的点击事件触发的,如果不阻止链接的默认操作,您将立即收到二次请求,浏览器将关闭先前的连接,而不等待响应完成。
当我忘记将 return false 添加到事件处理程序时,我遇到了同样的问题。

如果触发 ajax 的事件处理程序抛出异常,也会出现相同的症状。

仔细调试发出 ajax 请求的函数以及该函数的返回值。

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.

感受沵的脚步 2024-09-09 07:15:39

当浏览器关闭与服务器的连接时,就会发生管道损坏。这个问题之前发生在与

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.

云仙小弟 2024-09-09 07:15:39

我有一个可能相关的问题。

在 Windows 上使用 Safari 和 Chrome 时,在我的 django runserver 本地计算机上,一些视图随机不返回对 ajax POST 请求的响应。

解决方案是这样的:

我通过 POST 传递到视图的数据只是一个键/值对:“action=remove”。现在,我认为我实际上并没有使用这些数据。一旦我将数据分配给视图中的 var(即 foo = request.POST['action']),视图每次都会返回对 ajax 请求的响应。

绝对疯狂!

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!

还给你自由 2024-09-09 07:15:39

如果 JavaScript 客户端发生这种情况,解决方案可能如下。
您必须在事件处理程序的开头和结尾处添加 preventDefaultreturn false,例如:

$('#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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文