Search code examples
djangorestdjango-rest-frameworkdllpostman

DLL load failed while importing _rust: The specified procedure could not be found


I am trying to hit an API that is of POST type, it generates access and refresh tokens which can be used to access other APIs. It takes the username and password in the body, which we generate while creating a superuser (admin) in Django.

This is the detailed error I'm encountering while hitting the API in Postman:

Internal Server Error: /api/token/
Traceback (most recent call last):
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\django\core\handlers\exception.py", line 55, in inner 
    response = get_response(request)
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\django\views\decorators\csrf.py", line 56, in wrapper_view
    return view_func(*args, **kwargs)
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\django\views\generic\base.py", line 104, in view      
    return self.dispatch(request, *args, **kwargs)
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\rest_framework\views.py", line 509, in dispatch       
    response = self.handle_exception(exc)
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\rest_framework\views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\rest_framework\views.py", line 480, in raise_uncaught_exception
    raise exc
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\rest_framework\views.py", line 506, in dispatch       
    response = handler(request, *args, **kwargs)
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\rest_framework_simplejwt\views.py", line 44, in post  
    serializer.is_valid(raise_exception=True)
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\rest_framework\serializers.py", line 223, in is_valid 
    self._validated_data = self.run_validation(self.initial_data)
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\rest_framework\serializers.py", line 445, in run_validation
    value = self.validate(value)
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\rest_framework_simplejwt\serializers.py", line 77, in validate
    data["refresh"] = str(refresh)
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\rest_framework_simplejwt\tokens.py", line 95, in __str__
    return self.get_token_backend().encode(self.payload)
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\rest_framework_simplejwt\tokens.py", line 229, in get_token_backend
    return self.token_backend
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\rest_framework_simplejwt\tokens.py", line 222, in token_backend
    self._token_backend = import_string(
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\django\utils\module_loading.py", line 30, in import_string
    return cached_import(module_path, class_name)
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\django\utils\module_loading.py", line 15, in cached_import
    module = import_module(module_path)
  File "D:\Python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\rest_framework_simplejwt\state.py", line 1, in <module>
    from .backends import TokenBackend
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\rest_framework_simplejwt\backends.py", line 6, in <module>
    import jwt
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\jwt\__init__.py", line 1, in <module>
    from .api_jwk import PyJWK, PyJWKSet
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\jwt\api_jwk.py", line 7, in <module>
    from .algorithms import get_default_algorithms, has_crypto, requires_cryptography
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\jwt\algorithms.py", line 12, in <module>
    from .utils import (
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\jwt\utils.py", line 7, in <module>
    from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurve
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\cryptography\hazmat\primitives\asymmetric\ec.py", line 11, in <module>
    from cryptography.hazmat._oid import ObjectIdentifier
  File "C:\Users\kalash bhagwat\Desktop\Copods\Cloned Repos\leave-tracking-tool-backend\.venv\lib\site-packages\cryptography\hazmat\_oid.py", line 7, in <module>     
    from cryptography.hazmat.bindings._rust import (
ImportError: DLL load failed while importing _rust: The specified procedure could not be found.
[17/Apr/2024 15:14:58] "POST /api/token/ HTTP/1.1" 500 252726

I'm confused what to do, are some DLL files missing from my computer? These are some things which I've tried doing, but none worked:

  1. Update and Restart computer
  2. Tried updating and reinstalling cryptography package

Ideally, it should have returned the refresh and access tokens in response.


Solution

  • Upgrading python resolved this