为什么招摇会引发不清楚的错误 - Django [英] why swagger raises unclear error - Django

查看:14
本文介绍了为什么招摇会引发不清楚的错误 - Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 django rest 后端应用程序,我使用 swagger 来查看和记录我的 api 到 FE.

I have a django rest Backend app, and i use swagger to look and document my apis to the FE.

这很好,但我做了一些更改,现在我得到了这个错误:

This worked fine, but I made some changes and now I get this error:

Internal Server Error: /
Traceback (most recent call last):
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/views.py", line 497, in dispatch
    response = self.handle_exception(exc)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/views.py", line 457, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/views.py", line 468, in raise_uncaught_exception
    raise exc
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/views.py", line 494, in dispatch
    response = handler(request, *args, **kwargs)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework_swagger/views.py", line 32, in get
    schema = generator.get_schema(request=request)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/schemas/coreapi.py", line 153, in get_schema
    links = self.get_links(None if public else request)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/schemas/coreapi.py", line 140, in get_links
    link = view.schema.get_link(path, method, base_url=self.url)
AttributeError: 'AutoSchema' object has no attribute 'get_link'
HTTP GET / 500 [0.15, 127.0.0.1:44214]
/home/notsoshabby/Desktop/panda_pitch/django_project/settings.py 

这个错误不是很清楚,因为 AutoSchema 不是我的代码的一部分,并且回溯没有显示我的代码中的问题所在.我做了太多更改,无法一一检查并检查是哪一个导致了这种情况.

This error is not very clear as the AutoSchema is not a part of my code and the traceback is not showing me where in My code the problem is. I made too many changes to go one by one and check which one caused that.

以前有人遇到过这个问题吗?关于如何调试以查找导致此问题的更改的任何想法?

Anyone experienced this issue before? Any ideas on how to debug to find which change causes this issue?

推荐答案

我遇到了同样的问题,修复方法在这里描述:https://www.django-rest-framework.org/community/3.10-announcement/

I ran into the same issue, the fix is described here: https://www.django-rest-framework.org/community/3.10-announcement/

总而言之,Django Rest Framework 3.10(几天前发布)弃用了基于 CoreAPI 的模式生成,并引入了 OpenAPI 模式生成.目前要继续使用 django-rest-swagger,您需要通过将以下配置添加到设置文件来重新启用 CoreAPI 模式生成:

To summarize, Django Rest Framework 3.10 (released a few days ago) deprecated the CoreAPI based schema generation, and introduced the OpenAPI schema generation in its place. Currently to continue to use django-rest-swagger as is you need to re-enable the CoreAPI schema generation by adding the following config to the settings file:

REST_FRAMEWORK = { ... 'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema' }

这篇关于为什么招摇会引发不清楚的错误 - Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆