【问题标题】:django rest swagger unable to read apidjango rest swagger 无法读取 api
【发布时间】:2014-09-26 11:18:54
【问题描述】:

我已经在 urls.py 中设置了这个网址

url(r'^', include('rest_framework_swagger.urls', namespace='swagger')),

由于我不明白的原因,在从 localhost:8000 加载 swagger API UI 之后。任何 API 都无法扩展并出现此错误:

Unable to read api 'user' from path http://localhost:8000/api-docs/api/v1/user

我认为这是 url 中的 api-docs 的问题,但在删除它并再次重新获取之后。我得到了这些:

fetching resource list: http://localhost:8000/ 

在此之后我没有得到任何响应,或者如果我将 /api/v1 添加到 url 就会得到这个

403 : undefined http://localhost:8000/api/v1

这是我在 settings.py 中为招摇的:

SWAGGER_SETTINGS = {
    "exclude_namespaces": [], # List URL namespaces to ignore
    "api_version": 'alpha 1.0', # API's version
    "api_path": "/", # the path to API (it could not be a root level)
    "enabled_methods" : [ # method to enable in Swagger UI
        'get',
        'post',
        'delete'
    ],
    "api_key": '', # An API key
    "is_authentcated": False, # Set to True to enforce user authentication,
    "is_superuser": False, # Set to True to enforce admin only access
}

有人知道我在这里做错了什么吗?任何帮助,将不胜感激!谢谢。

【问题讨论】:

  • 我遇到了类似的错误。在我的情况下,我的字段规范中缺少逗号。即我有这个:字段=('id','company_info''serial_number','last_used_lat_lng','sensor_type','update_timestamp','last_used_tech')而不是这个字段=('id','company_info','序列号','last_used_lat_lng','sensor_type','update_timestamp','last_used_tech')
  • @SubodhNijsure 我的案例有点有趣,我使用了一个包含 url 的第三方插件。不知何故解决了这个问题......我删除了插件,然后一切正常。我仍然不知道到底是什么问题。
  • 在我的例子中,我收到了这个错误,因为我在 urls.py 文件中的 ViewSet 和 generics.ListAPIView 之间发生了冲突。

标签: django-rest-framework swagger


【解决方案1】:

与@SubodhNijsure 类似,我遇到了相关端点的运行时错误。当对端点信息的 JSON 调用失败时,尝试使用带有 /api-docs/ 前缀的 URL 似乎是 Swagger 的失败方式。

解决方案:修复我的运行时错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-21
    • 1970-01-01
    • 2014-06-05
    • 2016-12-06
    • 2014-06-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多