我正在制作一个web应用程序,后端使用django,前端使用Angular,我正在使用django TokenAuthentication进行身份验证,当我使用POSTMAN或REST框架接口测试请求时,一切正常,但当我尝试使用Angular制作POST时,我遇到下一个错误:
Exception happened during processing of request from ('127.0.0.1', 62030)
Traceback (most recent call last):
File "c:\users\eduar\anaconda3\Lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "c:\users\eduar\anaconda3\Lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "c:\users\eduar\anaconda3\Lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "c:\users\eduar\anaconda3\Lib\wsgiref\handlers.py", line 332, in send_headers
self.send_preamble()
File "c:\users\eduar\anaconda3\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\eduar\anaconda3\Lib\wsgiref\handlers.py", line 453, in _write
result = self.stdout.write(data)
File "c:\users\eduar\anaconda3\Lib\socketserver.py", line 799, in write
self._sock.sendall(b)
ConnectionAbortedError: [WinError 10053] Se ha anulado una conexión establecida por el software en su equipo host
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\eduar\anaconda3\Lib\wsgiref\handlers.py", line 141, in run
self.handle_error()
File "C:\Users\eduar\Desktop\zaito\env\lib\site-packages\django\core\servers\basehttp.py", line 116, in handle_error
super().handle_error()
File "c:\users\eduar\anaconda3\Lib\wsgiref\handlers.py", line 368, in handle_error
self.finish_response()
File "c:\users\eduar\anaconda3\Lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "c:\users\eduar\anaconda3\Lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "c:\users\eduar\anaconda3\Lib\wsgiref\handlers.py", line 331, in send_headers
if not self.origin_server or self.client_is_modern():
File "c:\users\eduar\anaconda3\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
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\eduar\anaconda3\Lib\socketserver.py", line 650, in process_request_thread
self.finish_request(request, client_address)
File "c:\users\eduar\anaconda3\Lib\socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "c:\users\eduar\anaconda3\Lib\socketserver.py", line 720, in __init__
self.handle()
File "C:\Users\eduar\Desktop\zaito\env\lib\site-packages\django\core\servers\basehttp.py", line 169, in handle
self.handle_one_request()
File "C:\Users\eduar\Desktop\zaito\env\lib\site-packages\django\core\servers\basehttp.py", line 194, in handle_one_request
handler.run(self.server.get_app())
File "c:\users\eduar\anaconda3\Lib\wsgiref\handlers.py", line 144, in run
self.close()
File "C:\Users\eduar\Desktop\zaito\env\lib\site-packages\django\core\servers\basehttp.py", line 111, in close
super().close()
File "c:\users\eduar\anaconda3\Lib\wsgiref\simple_server.py", line 35, in close
self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
Django代码:
你知道吗视图.py地址:
from rest_framework.authentication import TokenAuthentication
class LoginViewSet(viewsets.ViewSet):
serializer_class = AuthTokenSerializer
def create(self, request):
return ObtainAuthToken().post(request)
角度代码:
export class LoginService {
httpHeaders = new HttpHeaders({'Content-Type': 'application/json'});
baseUrl = environment.Server_url;
constructor(private http: HttpClient) {}
login(nameUser, passwordUser): Observable <any> {
const body = {username: nameUser , password: passwordUser};
for(var i = 0; i < 50; i++){
this.http.post(this.baseUrl + '/usersActions/login/', body , {headers: this.httpHeaders});
}
return this.http.post(this.baseUrl + '/usersActions/login/', body , {headers: this.httpHeaders});
}
目前没有回答
相关问题 更多 >
编程相关推荐