我正在使用 Djoser 从我的前端创建一个用户。当我使用此请求从 React 应用程序创建用户时
const newStudent = () => {
fetch(`${process.env.REACT_APP_SERVER_URL}/auth/users/`, {
method: 'POST',
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
email: "mss@domain.hr",
display_name: "Maa",
username: "as",
password: "sa",
role: 1
})
})
}
请求完成,新用户被创建,但这个很好的错误在 Django 控制台中弹出
----------------------------------------
Exception occurred during processing of request from ('192.168.1.6', 49473)
Traceback (most recent call last):
File "C:\Python39\lib\socketserver.py", line 650, in process_request_thread
self.finish_request(request, client_address)
File "C:\Python39\lib\socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Python39\lib\socketserver.py", line 720, in __init__
self.handle()
File "C:\Users\Mislav\.virtualenvs\backend-EBmKnWnA\lib\site-packages\django\core\servers\basehttp.py", line 174, in handle
self.handle_one_request()
File "C:\Users\Mislav\.virtualenvs\backend-EBmKnWnA\lib\site-packages\django\core\servers\basehttp.py", line 182, in handle_one_request
self.raw_requestline = self.rfile.readline(65537)
File "C:\Python39\lib\socket.py", line 704, in readinto
return self._sock.recv_into(b)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
----------------------------------------
有趣的是其他请求在套接字错误后工作正常
执行来自邮递员的完全相同的请求不会导致错误
[08/Apr/2021 13:15:46] "POST /auth/users/ HTTP/1.1" 201 104
我的 Djoser 设置
DJOSER = {
'USER_ID': 'id',
'LOGIN_FIELD' : 'username',
'LOGOUT_ON_PASSWORD_CHANGE': True,
'PASSWORD_RESET_CONFIRM_URL': 'password/reset/confirm/{uid}/{token}',
'ACTIVATION_URL': 'activate/{uid}/{token}',
'SEND_ACTIVATION_EMAIL': True,
'SERIALIZERS': {
'user_create': 'cmd_api.serializers.DUserSer',
'user': 'cmd_api.serializers.DUserSer',
'user_delete': 'djoser.serializers.UserDeleteSerializer',
}
}