8

有时当我查看终端时,我看到以下错误,谁能告诉我它正在显示以及如何避免它?

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
4

2 回答 2

6

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

1-/您的网址末尾缺少您可以通过在您请求的网址末尾添加“/”来修复它

2-您提出一些请求,然后迅速停止它。就像调用一个 url 然后取消调用并调用另一个 url。检查您在哪里拨打电话(JavaScript 或后端),并确保您在不取消它的情况下调用该 url。

于 2014-10-30T07:15:00.713 回答
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('/')
于 2014-01-17T11:29:23.630 回答