0

Class used to create pickled object in another module is inaccessible via running "python manage.py runserver". How do I point "manage.py" to that class (Classify)?

Here's my stack trace below:


    Internal Server Error: /api/digits/
    Traceback (most recent call last):
      File "C:\Users\DELL\Desktop\mnist-env\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
        response = get_response(request)
      File "C:\Users\DELL\Desktop\mnist-env\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
        response = wrapped_callback(request, *callback_args, **callback_kwargs)
      File "C:\Users\DELL\Desktop\mnist-env\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
        return view_func(*args, **kwargs)
      File "C:\Users\DELL\Desktop\mnist-env\lib\site-packages\rest_framework\viewsets.py", line 125, in view
        return self.dispatch(request, *args, **kwargs)
      File "C:\Users\DELL\Desktop\mnist-env\lib\site-packages\rest_framework\views.py", line 509, in dispatch
        response = self.handle_exception(exc)
      File "C:\Users\DELL\Desktop\mnist-env\lib\site-packages\rest_framework\views.py", line 469, in handle_exception
        self.raise_uncaught_exception(exc)
      File "C:\Users\DELL\Desktop\mnist-env\lib\site-packages\rest_framework\views.py", line 480, in raise_uncaught_exception
        raise exc
      File "C:\Users\DELL\Desktop\mnist-env\lib\site-packages\rest_framework\views.py", line 506, in dispatch
        response = handler(request, *args, **kwargs)
      File "C:\Users\DELL\Desktop\mnist-env\lib\site-packages\rest_framework\mixins.py", line 19, in create
        self.perform_create(serializer)
      File "C:\Users\DELL\Desktop\mnist-env\lib\site-packages\rest_framework\mixins.py", line 24, in perform_create
        serializer.save()
      File "C:\Users\DELL\Desktop\mnist-env\lib\site-packages\rest_framework\serializers.py", line 205, in save
        self.instance = self.create(validated_data)
      File "C:\Users\DELL\Desktop\mnist-env\lib\site-packages\rest_framework\serializers.py", line 939, in create
        instance = ModelClass._default_manager.create(**validated_data)
      File "C:\Users\DELL\Desktop\mnist-env\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
        return getattr(self.get_queryset(), name)(*args, **kwargs)
      File "C:\Users\DELL\Desktop\mnist-env\lib\site-packages\django\db\models\query.py", line 453, in create
        obj.save(force_insert=True, using=self.db)
      File "C:\Users\DELL\Desktop\mnist-env\MNIST_API\digits\models.py", line 62, in save
        pred = pickle.load(f)
    AttributeError: Can't get attribute 'Classify' on <module '__main__' from 'C:\\Users\\DELL\\Desktop\\mnist-env\\MNIST_API\\manage.py'>
    [05/Oct/2021 17:22:43] "POST /api/digits/ HTTP/1.1" 500 54505

Here's an image of my project file structure

P.s: The class is in the "mnist_classifier_scratch.py" file and I'm unpickling the object instantiated from that class in the models.py file.

JustCode
  • 21
  • 3
  • Did you change the module structure between `pickle.save` and `pickle.load`? – Willem Van Onsem Oct 05 '21 at 16:42
  • Does this answer your question? [Unable to load files using pickle and multiple modules](https://stackoverflow.com/questions/27732354/unable-to-load-files-using-pickle-and-multiple-modules) – Abdul Aziz Barkat Oct 05 '21 at 16:44
  • @WillemVanOnsem yes. The object is being saved from the same file the class 'Classify' resides and then being loaded in a separate file (models.py) in the parent directory housing the file containing the class as well as the pkl file – JustCode Oct 05 '21 at 18:11

0 Answers0