Django API Rest Framework and Angular 7 Authentication with jwt token












0














I am using Django Rest Framework for the back-end and Angular 7 for the user interface. I'm trying to create a login page to my single page application and authenticate with a jwt token. I've already managed the back-end and it works. Whenever i go to /api-token-auth/ and type the credentials i get a token in the rest framework interface.
The front-end part though troubles me. I have created the login component, the authorization service and a token interceptor. I believe i did the right adjustments but whenever i try to login from angular this error appears in the django command promt.




"Bad Request: /api-token-auth/ [19/Nov/2018 20:16:16] "POST
/api-token-auth/ HTTP/1.1" 400 68 Traceback (most recent call last):

File "C:Python36libwsgirefhandlers.py", line 138, in run
self.finish_response() File "C:Python36libwsgirefhandlers.py", line 180, in finish_response
self.write(data) File "C:Python36libwsgirefhandlers.py", line 274, in write
self.send_headers() File "C:Python36libwsgirefhandlers.py", line 332, in send_headers
self.send_preamble() File "C:Python36libwsgirefhandlers.py", line 255, in send_preamble
('Date: %srn' % format_date_time(time.time())).encode('iso-8859-1') File
"C:Python36libwsgirefhandlers.py", line 453, in _write
result = self.stdout.write(data) File "C:Python36libsocketserver.py", line 775, in write
self._sock.sendall(b) ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host
machine [19/Nov/2018 20:16:16] "POST /api-token-auth/ HTTP/1.1" 500 59
---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 51566) Traceback (most recent
call last): File "C:Python36libwsgirefhandlers.py", line 138, in
run
self.finish_response() File "C:Python36libwsgirefhandlers.py", line 180, in finish_response
self.write(data) File "C:Python36libwsgirefhandlers.py", line 274, in write
self.send_headers() File "C:Python36libwsgirefhandlers.py", line 332, in send_headers
self.send_preamble() File "C:Python36libwsgirefhandlers.py", line 255, in send_preamble
('Date: %srn' % format_date_time(time.time())).encode('iso-8859-1') File
"C:Python36libwsgirefhandlers.py", line 453, in _write
result = self.stdout.write(data) File "C:Python36libsocketserver.py", line 775, in write
self._sock.sendall(b) ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host
machine



During handling of the above exception, another exception occurred:



Traceback (most recent call last): File
"C:Python36libwsgirefhandlers.py", line 141, in run
self.handle_error() File "C:Python36libsite-packagesdjangocoreserversbasehttp.py", line
86, in handle_error
super().handle_error() File "C:Python36libwsgirefhandlers.py", line 368, in handle_error
self.finish_response() File "C:Python36libwsgirefhandlers.py", line 180, in finish_response
self.write(data) File "C:Python36libwsgirefhandlers.py", line 274, in write
self.send_headers() File "C:Python36libwsgirefhandlers.py", line 331, in send_headers
if not self.origin_server or self.client_is_modern(): File "C:Python36libwsgirefhandlers.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:Python36libsocketserver.py", line 639, in process_request_thread
self.finish_request(request, client_address) File "C:Python36libsocketserver.py", line 361, in finish_request
self.RequestHandlerClass(request, client_address, self) File "C:Python36libsocketserver.py", line 696, in init
self.handle() File "C:Python36libsite-packagesdjangocoreserversbasehttp.py", line
154, in handle
handler.run(self.server.get_app()) File "C:Python36libwsgirefhandlers.py", line 144, in run
self.close() File "C:Python36libwsgirefsimple_server.py", line 35, in close
self.status.split(' ',1)[0], self.bytes_sent AttributeError: 'NoneType' object has no attribute 'split'"




I'm really trying to understand what is going on based in this error. Anybody has an idea? Thanks










share|improve this question



























    0














    I am using Django Rest Framework for the back-end and Angular 7 for the user interface. I'm trying to create a login page to my single page application and authenticate with a jwt token. I've already managed the back-end and it works. Whenever i go to /api-token-auth/ and type the credentials i get a token in the rest framework interface.
    The front-end part though troubles me. I have created the login component, the authorization service and a token interceptor. I believe i did the right adjustments but whenever i try to login from angular this error appears in the django command promt.




    "Bad Request: /api-token-auth/ [19/Nov/2018 20:16:16] "POST
    /api-token-auth/ HTTP/1.1" 400 68 Traceback (most recent call last):

    File "C:Python36libwsgirefhandlers.py", line 138, in run
    self.finish_response() File "C:Python36libwsgirefhandlers.py", line 180, in finish_response
    self.write(data) File "C:Python36libwsgirefhandlers.py", line 274, in write
    self.send_headers() File "C:Python36libwsgirefhandlers.py", line 332, in send_headers
    self.send_preamble() File "C:Python36libwsgirefhandlers.py", line 255, in send_preamble
    ('Date: %srn' % format_date_time(time.time())).encode('iso-8859-1') File
    "C:Python36libwsgirefhandlers.py", line 453, in _write
    result = self.stdout.write(data) File "C:Python36libsocketserver.py", line 775, in write
    self._sock.sendall(b) ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host
    machine [19/Nov/2018 20:16:16] "POST /api-token-auth/ HTTP/1.1" 500 59
    ---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 51566) Traceback (most recent
    call last): File "C:Python36libwsgirefhandlers.py", line 138, in
    run
    self.finish_response() File "C:Python36libwsgirefhandlers.py", line 180, in finish_response
    self.write(data) File "C:Python36libwsgirefhandlers.py", line 274, in write
    self.send_headers() File "C:Python36libwsgirefhandlers.py", line 332, in send_headers
    self.send_preamble() File "C:Python36libwsgirefhandlers.py", line 255, in send_preamble
    ('Date: %srn' % format_date_time(time.time())).encode('iso-8859-1') File
    "C:Python36libwsgirefhandlers.py", line 453, in _write
    result = self.stdout.write(data) File "C:Python36libsocketserver.py", line 775, in write
    self._sock.sendall(b) ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host
    machine



    During handling of the above exception, another exception occurred:



    Traceback (most recent call last): File
    "C:Python36libwsgirefhandlers.py", line 141, in run
    self.handle_error() File "C:Python36libsite-packagesdjangocoreserversbasehttp.py", line
    86, in handle_error
    super().handle_error() File "C:Python36libwsgirefhandlers.py", line 368, in handle_error
    self.finish_response() File "C:Python36libwsgirefhandlers.py", line 180, in finish_response
    self.write(data) File "C:Python36libwsgirefhandlers.py", line 274, in write
    self.send_headers() File "C:Python36libwsgirefhandlers.py", line 331, in send_headers
    if not self.origin_server or self.client_is_modern(): File "C:Python36libwsgirefhandlers.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:Python36libsocketserver.py", line 639, in process_request_thread
    self.finish_request(request, client_address) File "C:Python36libsocketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self) File "C:Python36libsocketserver.py", line 696, in init
    self.handle() File "C:Python36libsite-packagesdjangocoreserversbasehttp.py", line
    154, in handle
    handler.run(self.server.get_app()) File "C:Python36libwsgirefhandlers.py", line 144, in run
    self.close() File "C:Python36libwsgirefsimple_server.py", line 35, in close
    self.status.split(' ',1)[0], self.bytes_sent AttributeError: 'NoneType' object has no attribute 'split'"




    I'm really trying to understand what is going on based in this error. Anybody has an idea? Thanks










    share|improve this question

























      0












      0








      0







      I am using Django Rest Framework for the back-end and Angular 7 for the user interface. I'm trying to create a login page to my single page application and authenticate with a jwt token. I've already managed the back-end and it works. Whenever i go to /api-token-auth/ and type the credentials i get a token in the rest framework interface.
      The front-end part though troubles me. I have created the login component, the authorization service and a token interceptor. I believe i did the right adjustments but whenever i try to login from angular this error appears in the django command promt.




      "Bad Request: /api-token-auth/ [19/Nov/2018 20:16:16] "POST
      /api-token-auth/ HTTP/1.1" 400 68 Traceback (most recent call last):

      File "C:Python36libwsgirefhandlers.py", line 138, in run
      self.finish_response() File "C:Python36libwsgirefhandlers.py", line 180, in finish_response
      self.write(data) File "C:Python36libwsgirefhandlers.py", line 274, in write
      self.send_headers() File "C:Python36libwsgirefhandlers.py", line 332, in send_headers
      self.send_preamble() File "C:Python36libwsgirefhandlers.py", line 255, in send_preamble
      ('Date: %srn' % format_date_time(time.time())).encode('iso-8859-1') File
      "C:Python36libwsgirefhandlers.py", line 453, in _write
      result = self.stdout.write(data) File "C:Python36libsocketserver.py", line 775, in write
      self._sock.sendall(b) ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host
      machine [19/Nov/2018 20:16:16] "POST /api-token-auth/ HTTP/1.1" 500 59
      ---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 51566) Traceback (most recent
      call last): File "C:Python36libwsgirefhandlers.py", line 138, in
      run
      self.finish_response() File "C:Python36libwsgirefhandlers.py", line 180, in finish_response
      self.write(data) File "C:Python36libwsgirefhandlers.py", line 274, in write
      self.send_headers() File "C:Python36libwsgirefhandlers.py", line 332, in send_headers
      self.send_preamble() File "C:Python36libwsgirefhandlers.py", line 255, in send_preamble
      ('Date: %srn' % format_date_time(time.time())).encode('iso-8859-1') File
      "C:Python36libwsgirefhandlers.py", line 453, in _write
      result = self.stdout.write(data) File "C:Python36libsocketserver.py", line 775, in write
      self._sock.sendall(b) ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host
      machine



      During handling of the above exception, another exception occurred:



      Traceback (most recent call last): File
      "C:Python36libwsgirefhandlers.py", line 141, in run
      self.handle_error() File "C:Python36libsite-packagesdjangocoreserversbasehttp.py", line
      86, in handle_error
      super().handle_error() File "C:Python36libwsgirefhandlers.py", line 368, in handle_error
      self.finish_response() File "C:Python36libwsgirefhandlers.py", line 180, in finish_response
      self.write(data) File "C:Python36libwsgirefhandlers.py", line 274, in write
      self.send_headers() File "C:Python36libwsgirefhandlers.py", line 331, in send_headers
      if not self.origin_server or self.client_is_modern(): File "C:Python36libwsgirefhandlers.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:Python36libsocketserver.py", line 639, in process_request_thread
      self.finish_request(request, client_address) File "C:Python36libsocketserver.py", line 361, in finish_request
      self.RequestHandlerClass(request, client_address, self) File "C:Python36libsocketserver.py", line 696, in init
      self.handle() File "C:Python36libsite-packagesdjangocoreserversbasehttp.py", line
      154, in handle
      handler.run(self.server.get_app()) File "C:Python36libwsgirefhandlers.py", line 144, in run
      self.close() File "C:Python36libwsgirefsimple_server.py", line 35, in close
      self.status.split(' ',1)[0], self.bytes_sent AttributeError: 'NoneType' object has no attribute 'split'"




      I'm really trying to understand what is going on based in this error. Anybody has an idea? Thanks










      share|improve this question













      I am using Django Rest Framework for the back-end and Angular 7 for the user interface. I'm trying to create a login page to my single page application and authenticate with a jwt token. I've already managed the back-end and it works. Whenever i go to /api-token-auth/ and type the credentials i get a token in the rest framework interface.
      The front-end part though troubles me. I have created the login component, the authorization service and a token interceptor. I believe i did the right adjustments but whenever i try to login from angular this error appears in the django command promt.




      "Bad Request: /api-token-auth/ [19/Nov/2018 20:16:16] "POST
      /api-token-auth/ HTTP/1.1" 400 68 Traceback (most recent call last):

      File "C:Python36libwsgirefhandlers.py", line 138, in run
      self.finish_response() File "C:Python36libwsgirefhandlers.py", line 180, in finish_response
      self.write(data) File "C:Python36libwsgirefhandlers.py", line 274, in write
      self.send_headers() File "C:Python36libwsgirefhandlers.py", line 332, in send_headers
      self.send_preamble() File "C:Python36libwsgirefhandlers.py", line 255, in send_preamble
      ('Date: %srn' % format_date_time(time.time())).encode('iso-8859-1') File
      "C:Python36libwsgirefhandlers.py", line 453, in _write
      result = self.stdout.write(data) File "C:Python36libsocketserver.py", line 775, in write
      self._sock.sendall(b) ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host
      machine [19/Nov/2018 20:16:16] "POST /api-token-auth/ HTTP/1.1" 500 59
      ---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 51566) Traceback (most recent
      call last): File "C:Python36libwsgirefhandlers.py", line 138, in
      run
      self.finish_response() File "C:Python36libwsgirefhandlers.py", line 180, in finish_response
      self.write(data) File "C:Python36libwsgirefhandlers.py", line 274, in write
      self.send_headers() File "C:Python36libwsgirefhandlers.py", line 332, in send_headers
      self.send_preamble() File "C:Python36libwsgirefhandlers.py", line 255, in send_preamble
      ('Date: %srn' % format_date_time(time.time())).encode('iso-8859-1') File
      "C:Python36libwsgirefhandlers.py", line 453, in _write
      result = self.stdout.write(data) File "C:Python36libsocketserver.py", line 775, in write
      self._sock.sendall(b) ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host
      machine



      During handling of the above exception, another exception occurred:



      Traceback (most recent call last): File
      "C:Python36libwsgirefhandlers.py", line 141, in run
      self.handle_error() File "C:Python36libsite-packagesdjangocoreserversbasehttp.py", line
      86, in handle_error
      super().handle_error() File "C:Python36libwsgirefhandlers.py", line 368, in handle_error
      self.finish_response() File "C:Python36libwsgirefhandlers.py", line 180, in finish_response
      self.write(data) File "C:Python36libwsgirefhandlers.py", line 274, in write
      self.send_headers() File "C:Python36libwsgirefhandlers.py", line 331, in send_headers
      if not self.origin_server or self.client_is_modern(): File "C:Python36libwsgirefhandlers.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:Python36libsocketserver.py", line 639, in process_request_thread
      self.finish_request(request, client_address) File "C:Python36libsocketserver.py", line 361, in finish_request
      self.RequestHandlerClass(request, client_address, self) File "C:Python36libsocketserver.py", line 696, in init
      self.handle() File "C:Python36libsite-packagesdjangocoreserversbasehttp.py", line
      154, in handle
      handler.run(self.server.get_app()) File "C:Python36libwsgirefhandlers.py", line 144, in run
      self.close() File "C:Python36libwsgirefsimple_server.py", line 35, in close
      self.status.split(' ',1)[0], self.bytes_sent AttributeError: 'NoneType' object has no attribute 'split'"




      I'm really trying to understand what is going on based in this error. Anybody has an idea? Thanks







      django angular django-rest-framework jwt






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 '18 at 18:30









      Thanos GanjaThanos Ganja

      11




      11
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380661%2fdjango-api-rest-framework-and-angular-7-authentication-with-jwt-token%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380661%2fdjango-api-rest-framework-and-angular-7-authentication-with-jwt-token%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

          ts Property 'filter' does not exist on type '{}'

          mat-slide-toggle shouldn't change it's state when I click cancel in confirmation window