使用pickle.load在uwsgi上反序列化自定义对象时发生AttributeError:无法在<module'__main __'(内置)>上获取属性'ModelConfig'

时间:2019-11-22 08:13:17

标签: python-3.x pickle uwsgi

堆栈跟踪如下:

Traceback (most recent call last):
  File "/root/anaconda3/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/root/anaconda3/lib/python3.6/site-packages/django/utils/deprecation.py", line 90, in __call__
    response = self.process_request(request)
  File "/root/anaconda3/lib/python3.6/site-packages/django/middleware/common.py", line 52, in process_request
    if self.should_redirect_with_slash(request):
  File "/root/anaconda3/lib/python3.6/site-packages/django/middleware/common.py", line 70, in should_redirect_with_slash
    not is_valid_path(request.path_info, urlconf) and
  File "/root/anaconda3/lib/python3.6/site-packages/django/urls/base.py", line 157, in is_valid_path
    resolve(path, urlconf)
  File "/root/anaconda3/lib/python3.6/site-packages/django/urls/base.py", line 24, in resolve
    return get_resolver(urlconf).resolve(path)
  File "/root/anaconda3/lib/python3.6/site-packages/django/urls/resolvers.py", line 491, in resolve
    for pattern in self.url_patterns:
  File "/root/anaconda3/lib/python3.6/site-packages/django/utils/functional.py", line 37, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/root/anaconda3/lib/python3.6/site-packages/django/urls/resolvers.py", line 533, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/root/anaconda3/lib/python3.6/site-packages/django/utils/functional.py", line 37, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/root/anaconda3/lib/python3.6/site-packages/django/urls/resolvers.py", line 526, in urlconf_module
    return import_module(self.urlconf_name)
  File "/root/anaconda3/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "./sendPost/urls.py", line 18, in <module>
    from sendPostText import views
  File "./sendPostText/views.py", line 106, in <module>
    cnn_models = get_model()
  File "./sendPostText/views.py", line 100, in get_model
    Model.update_filter_list(model_path)
  File "./sendPostText/MutiTagRecogByNN/modelObjs1.py", line 168, in update_filter_list
    list = cls.get_specific_filter_list(model_dir)
  File "./sendPostText/MutiTagRecogByNN/modelObjs1.py", line 161, in get_specific_filter_list
    mc = pickle.load(f)
AttributeError: Can't get attribute 'ModelConfig' on <module '__main__' (built-in)>

类'ModelConfig'是在模块'modelObjs1'中定义的类,我尝试用pickle反序列化'modelObjs1'中'ModelConfig'类的对象。 使用django作为服务器运行项目时遇到类似的错误,我通过将类导入到'manage.py'解决了该问题。 但是在使用uwsgi运行时,我不知道模块'__main __'(内置)是什么以及如何解决它。

0 个答案:

没有答案