3

Estoy desarrollando una aplicación web, usando django REST para el Back-end y Angular para el Front-end, la aplicación para la autenticación de usuarios usa el TokenAuthentication del propio django REST, cuando pruebo hacer POST al Django para obtener el token de autenticación desde Postman o desde la interfaz del propio django, no hay ningún problema, pero al momento de hacer el post con un servicio desde Angular me sale siguiente error:

 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'

Este el codigo en django:

views.py:

from rest_framework.authentication import TokenAuthentication

class LoginViewSet(viewsets.ViewSet):
    """ check username and password and return an auth token """

    serializer_class = AuthTokenSerializer

    def create(self, request):
        """ Use the obtainAuthToken to validate and create a token"""
        return ObtainAuthToken().post(request)

Codigo de Angular:

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});
  }
1
  • Encontraste alguna solución? Me sale un error bastante parecido, pero en otro programa en GNS3 el 13 jul. 2020 a las 5:32

0

Tu Respuesta

Al pulsar en “Publica tu respuesta”, muestras tu consentimiento a nuestros términos de servicio, política de privacidad y política de cookies

Examina otras preguntas con la etiqueta o formula tu propia pregunta.