姜戈 + WebKit = 管道破损
我正在运行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这不是 Django 问题。您的浏览器很可能执行了错误的操作。
查看此 Django 票证了解更多信息。
This is not a Django issue. Your browser is most likely doing something erroneous.
Check this Django ticket for more info.
我最近刚刚在 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.
这可能是由于调度 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.
当浏览器关闭与服务器的连接时,就会发生管道损坏。这个问题之前发生在与
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 adde.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.我有一个可能相关的问题。
在 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!
如果
JavaScript
客户端发生这种情况,解决方案可能如下。您必须在事件处理程序的开头和结尾处添加
preventDefault
和return false
,例如:In the case that this happens with a
JavaScript
client, a solution could be the following.You have to add
preventDefault
andreturn false
at beginning and at the end of your event handler like: