当客户端服务器试图通过JAVA套接字访问我的django API时,发生以下错误。
我正在使用Python的本地服务器
Exception happened during processing of request from ('192.168.10.36',
59028)
Traceback (most recent call last):
File "D:\ProgramFiles\Python\Python36\lib\socketserver.py", line 651, in
process_request_thread
self.finish_request(request, client_address)
File "D:\ProgramFiles\Python\Python36\lib\socketserver.py", line 361, in
finish_request
self.RequestHandlerClass(request, client_address, self)
File "D:\ProgramFiles\Python\Python36\lib\socketserver.py", line 721, in
__init__
self.handle()
File "D:\ProgramFiles\Python\Python36\lib\site-
packages\django\core\servers\basehttp.py", line 153, in handle
self.handle_one_request()
File "D:\ProgramFiles\Python\Python36\lib\site-
packages\django\core\servers\basehttp.py", line 161, in handle_one_request
self.raw_requestline = self.rfile.readline(65537)
File "D:\ProgramFiles\Python\Python36\lib\socket.py", line 586, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly
closed by the remote host
我的API代码如下:
def API_detect(self, request):
"""Start the script"""
serializer = serializers.DetectionSerializer(data=request.data)
if serializer.is_valid():
on_off = serializer.data.get('checker')
if on_off == "start":
print("on")
if on_off == "stop":
print("off")
m = 'Received {0}'.format(on_off)
return Response({'message': m})
else:
return Response(
serializer.errors, status=status.HTTP_400_BAD_REQUEST)