错误:[Errno 32]破管 [英] error: [Errno 32] Broken pipe

查看:633
本文介绍了错误:[Errno 32]破管的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Django项目。一切顺利,直到我创建了一个Ajax请求,将值从html页面发送到后端(views.py)。



当我使用Ajax发送数据时,我可以查看传递给views.py的值,甚至达到render_to_response方法并显示我的页面,但是在终端中抛出错误的管道错误。我没有看到任何程序的中断,但我想知道是否有办法防止这种错误发生。我检查了其他答复。但是没有运气到目前为止。



当我在刷新的页面上再次点击提交时,我收到以下消息:


您正在寻找的页面使用您输入的信息。返回该页面可能会导致您重复的任何操作。你想继续吗? [提交] [取消]`


这是转储:

 追溯(最近呼叫最后):
---------------------- ------------------
('127.0.0.1',34812)处理请求时发生异常
-------- --------------------------------
文件/usr/lib/python2.7/dist-packages /django/core/servers/basehttp.py,第284行,运行
self.finish_response()
文件/usr/lib/python2.7/dist-packages/django/core/servers /basehttp.py,第324行,在finish_response
self.write(data)
文件/usr/lib/python2.7/dist-packages/django/core/servers/basehttp.py ,第403行,写
self.send_headers()
文件/usr/lib/python2.7/dist-packages/django/core/servers/basehttp.py,第467行,在send_headers
self.send_preamble()
文件/usr/lib/python2.7/dist-packages/django/core/servers/basehttp.py,第385行,send_preamble
'日期:%s\r\ n'%http_date()
文件/usr/lib/python2.7/socket.py,第324行,写入
self.flush()
文件/ usr / lib /python2.7/socket.py,第303行,flush
self._sock.sendall(view [write_offset:write_offset + buffer_size])
error:[Errno 32] Broken pipe

追溯(最近的最后一次调用):
文件/usr/lib/python2.7/SocketServer.py,第284行,_handle_request_noblock
self.process_request(request,client_address)
文件/usr/lib/python2.7/SocketServer.py,第310行,process_request
self.finish_request(request,client_address)
文件/usr/lib/python2.7 /SocketServer.py,第323行,在finish_request
self.RequestHandlerClass(request,client_address,self)
文件/usr/lib/python2.7/dist-packages/django/core/servers/ basehttp.py,第570行,__init__
BaseHTTPRequestHandler .__ init __(self,* args,** kwargs)
文件/usr/lib/python2.7/SocketServer.py,第640行,在__init__
self.finish()
文件/usr/lib/python2.7/SocketServer.py,第693行,完成
self.wfile.flush()
文件/usr/lib/python2.7 /socket.py,行303,in flush
self._sock.sendall(view [write_offset:write_offset + buffer_size])
error:[Errno 32] Broken pipe

更新:
这是我发送的代码:

  $(document).ready(function(){
$ .csrftoken();
$(#submitdata)。click(function(){
// values = [tmode,fmode,t_cool,t_heat,hold];
values = {
tmode:tmode,
fmode:fmode,
t_cool:t_cool,
t_heat:t_heat,
hold:hold
};
var jsonText = JSON.stringify(values);
$ .ajax({
url:/ submitdata /,
type:'POST',
data :jsonText,
dataType:'json',
success:function(data){
console.log(data.success);
},
complete:function (){
console.log('complete');
},
错误:function(xhr,textStatus,thrownError){
console.log(thrownError);
console.log(obj);
}
});
});
});

这里是我的views.py:

  @login_required 
def submitvalues(request):
#context = RequestContext(request)
如果request.POST:
jsonvalues = json .loads(request.raw_post_data)
print jsonvalues
return HttpResponse(json.dumps(dict(status ='updated')),mimetype =application / json)

我仍然面临同样的问题。有人可以帮助我吗?



编辑于5/28/2014:
我只是想出了一个破碎的管道的原因。这是因为我没有发回Python的响应,只是期望页面自动刷新。我是所有这一切的新手,花了我一段时间,弄清楚为什么会发生这种情况。

解决方案

您尚未发布任何代码,但这可能是因为您在按钮提交但避风港时触发了Ajax请求不会阻止默认操作。所以Ajax请求是做出来的,但是在返回数据的时候,浏览器已经请求了下一页,所以没有什么可以收到的。


I am working on a Django project. All went well till I created an Ajax request to send values from the html page to the backend (views.py).

When I send the data using Ajax, I am able to view the values being passed to views.py, and it even reaches the render_to_response method and displays my page, but throws the broken pipe error in the terminal. I don't see any kind of disruption to the program, but I wanted to know if there is a way to prevent this error from occurring. I checked the other responses. But no luck so far.

When I try to hit submit again on the refreshed page, I get this message:

The page that you're looking for used information that you entered. Returning to that page might cause any action you took to be repeated. Do you want to continue? [Submit] [Cancel]`

Here is the dump:

    Traceback (most recent call last):
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 34812)
----------------------------------------
  File "/usr/lib/python2.7/dist-packages/django/core/servers/basehttp.py", line 284, in run
    self.finish_response()
  File "/usr/lib/python2.7/dist-packages/django/core/servers/basehttp.py", line 324, in finish_response
    self.write(data)
  File "/usr/lib/python2.7/dist-packages/django/core/servers/basehttp.py", line 403, in write
    self.send_headers()
  File "/usr/lib/python2.7/dist-packages/django/core/servers/basehttp.py", line 467, in send_headers
    self.send_preamble()
  File "/usr/lib/python2.7/dist-packages/django/core/servers/basehttp.py", line 385, in send_preamble
    'Date: %s\r\n' % http_date()
  File "/usr/lib/python2.7/socket.py", line 324, in write
    self.flush()
  File "/usr/lib/python2.7/socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe

Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 310, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/dist-packages/django/core/servers/basehttp.py", line 570, in __init__
    BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
  File "/usr/lib/python2.7/SocketServer.py", line 640, in __init__
    self.finish()
  File "/usr/lib/python2.7/SocketServer.py", line 693, in finish
    self.wfile.flush()
  File "/usr/lib/python2.7/socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe

Update: Here is the code that I am sending:

    $( document ).ready(function() {
$.csrftoken();
$("#submitdata").click(function(){
    //values = [tmode, fmode, t_cool, t_heat, hold];
    values = {
    "tmode": tmode,
    "fmode": fmode,
    "t_cool": t_cool,
    "t_heat": t_heat,
    "hold": hold
    };
    var jsonText = JSON.stringify(values);
    $.ajax({
        url: "/submitdata/",
        type: 'POST',
        data: jsonText,
        dataType: 'json',
        success:function(data){
            console.log(data.success);
        },
        complete:function(){
            console.log('complete');
        },
        error:function (xhr, textStatus, thrownError){
            console.log(thrownError);
            console.log(obj);
        }
    });       
});
});

And here is my views.py:

@login_required
def submitvalues(request):
    #context = RequestContext(request)
    if request.POST:
        jsonvalues = json.loads(request.raw_post_data)
        print jsonvalues
        return HttpResponse(json.dumps(dict(status='updated')), mimetype="application/json")

I am still facing the same issue. Can someone help me with this?

Edit on 5/28/2014: I just figured out the reason for a Broken Pipe. It was because I was not sending back the response from Python and was just expecting the page to refresh automatically. I am a newbie to all of this, and took me a while to figure out why this happened.

解决方案

You haven't posted any code, but this is probably because you have triggered the Ajax request on a button submit but haven't prevented the default action. So the Ajax request is made, but by the time it comes to return the data, the browser has already requested the next page anyway, so there is nothing to receive it.

这篇关于错误:[Errno 32]破管的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆