错误:[Errno 32]破管django

时间:2013-11-20 18:21:43

标签: django broken-pipe

有时当我看到我的终端时,我看到以下错误,有人可以告诉我它是否正在显示以及如何避免它?

Exception happened during processing of request from ('127.0.0.1', 39444)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 582, in process_request_thread
    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 "/home/comp/Envs/proj/local/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 150, in __init__
    super(WSGIRequestHandler, self).__init__(*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

2 个答案:

答案 0 :(得分:3)

由于以下两个原因,您会收到该错误。 由于其他原因,您可能会看到相同的问题

1 - 您在网址末尾遗漏了/,您可以通过添加" /"来修复它。到您请求的URL的末尾

2 - 您提出了一些请求然后快速停止它。就像拨打网址一样,然后取消通话并拨打另一个网址。检查您拨打电话的位置(JavaScript或后端),并确保在不取消它的情况下调用网址。

答案 1 :(得分:2)

这可能是因为您使用两种方法将数据插入数据库,这会导致网站速度变慢。

def add_subscriber(request, email=None):
    if request.method == 'POST':
        email = request.POST['email_field']
        e = Subscriber.objects.create(email=email).save()  <==== 
        return HttpResponseRedirect('/')
    else:
        return HttpResponseRedirect('/')

例如。在上面的函数错误是箭头指向的地方 上面实现的正确方法是

def add_subscriber(request, email=None):
    if request.method == 'POST':
        email = request.POST['email_field']
        e = Subscriber.objects.create(email=email)
        return HttpResponseRedirect('/')
    else:
        return HttpResponseRedirect('/')