Django Closed Socket Error Repeated AJAX Calls[WinError 10053]主机中的软件中止了已建立的连接

2024-10-01 09:34:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过我的django1.11.4项目中的jquery插件Select2实现一个实时搜索。运行python3.6。当我在文本框中输入时,服务器似乎无法处理请求的数量,它关闭,然后出现以下一系列错误。 我花了几个小时跟踪了SOSO(more)Googleetc上的几个线程,但是没有一个是有效的解决方案。我原以为是python版本的问题,但我已经从2.7升级到3.6,现在仍然存在。任何帮助都很好谢谢!在

这是ajax调用所调用的视图:

  def directory_search(request):
      # Query text from search bar
      query = request.GET.get('q', None)
      if query:

          # Searches the DB for matching value
          customers = Customer.objects.filter(
              Q(name__icontains= query)|
              Q(contract_account__icontains= query)|
              Q(address__icontains= query)|
              Q(address__icontains= query)|
              Q(email__icontains= query)
              ).distinct()
          # Turns queryset into dict
          customers = customers.values("contract_account","name")
          # Turns dict into list
          customers_list = list(customers)

          return JsonResponse(customers_list, safe=False)
      else:
          return JsonResponse(data={'success': False,'errors': 'No mathing items found'})

这是Select2插件的js/ajax调用:

^{pr2}$

错误:(我只是把它们拆开让它更清晰,但它们是按顺序出现的)

1。在

Traceback (most recent call last):
  File "C:\Users\leep\AppData\Local\Programs\Python\Python36-32\lib\wsgiref\handlers.py", line 138, in run
    self.finish_response()
  File "C:\Users\leep\AppData\Local\Programs\Python\Python36-32\lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "C:\Users\leep\AppData\Local\Programs\Python\Python36-32\lib\wsgiref\handlers.py", line 274, in write
    self.send_headers()
  File "C:\Users\leep\AppData\Local\Programs\Python\Python36-32\lib\wsgiref\handlers.py", line 332, in send_headers
    self.send_preamble()
  File "C:\Users\leep\AppData\Local\Programs\Python\Python36-32\lib\wsgiref\handlers.py", line 255, in send_preamble
    ('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
  File "C:\Users\leep\AppData\Local\Programs\Python\Python36-32\lib\wsgiref\handlers.py", line 453, in _write
    result = self.stdout.write(data)
  File "C:\Users\leep\AppData\Local\Programs\Python\Python36-32\lib\socketserver.py", line 775, in write
    self._sock.sendall(b)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

2。在

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\leep\AppData\Local\Programs\Python\Python36-32\lib\wsgiref\handlers.py", line 141, in run
    self.handle_error()
  File "C:\Users\leep\PythonStuff\virtual_environments\rpp_3.6\lib\site-packages\django\core\servers\basehttp.py", line 88, in handle_error
    super(ServerHandler, self).handle_error()
  File "C:\Users\leep\AppData\Local\Programs\Python\Python36-32\lib\wsgiref\handlers.py", line 368, in handle_error
    self.finish_response()
  File "C:\Users\leep\AppData\Local\Programs\Python\Python36-32\lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "C:\Users\leep\AppData\Local\Programs\Python\Python36-32\lib\wsgiref\handlers.py", line 274, in write
    self.send_headers()
  File "C:\Users\leep\AppData\Local\Programs\Python\Python36-32\lib\wsgiref\handlers.py", line 331, in send_headers
    if not self.origin_server or self.client_is_modern():
  File "C:\Users\leep\AppData\Local\Programs\Python\Python36-32\lib\wsgiref\handlers.py", line 344, in client_is_modern
    return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable

3。在

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Users\leep\AppData\Local\Programs\Python\Python36-32\lib\socketserver.py", line 639, in process_request_thread
    self.finish_request(request, client_address)
  File "C:\Users\leep\AppData\Local\Programs\Python\Python36-32\lib\socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Users\leep\AppData\Local\Programs\Python\Python36-32\lib\socketserver.py", line 696, in __init__
    self.handle()
  File "C:\Users\leep\PythonStuff\virtual_environments\rpp_3.6\lib\site-packages\django\core\servers\basehttp.py", line 155, in handle
    handler.run(self.server.get_app())
  File "C:\Users\leep\AppData\Local\Programs\Python\Python36-32\lib\wsgiref\handlers.py", line 144, in run
    self.close()
  File "C:\Users\leep\AppData\Local\Programs\Python\Python36-32\lib\wsgiref\simple_server.py", line 35, in close
    self.status.split(' ',1)[0], self.bytes_sent
  AttributeError: 'NoneType' object has no attribute 'split'

Tags: inpyselfrequestliblocalhandlersline
1条回答
网友
1楼 · 发布于 2024-10-01 09:34:59

它似乎是一个python 2.7已知的bug,可能它仍然存在于python 3.6上:

https://bugs.python.org/issue14574

我在运行python3.6的django中也遇到了类似的问题 TypeError: 'NoneType' object is not subscriptable followed by AttributeError: 'NoneType' object has no attribute 'split'

编辑

看来是chrome出错了。我没有想到,因为我用的是Opera,但Opera也用铬。在internet explorer中没有显示错误。在

https://code.djangoproject.com/ticket/21227#no1

这是窃听器

相关问题 更多 >