Tobitor
Tobitor

Reputation: 1508

Flasgger: Swagger App - http://127.0.0.1:5000/apidocs/ - Fetch errorINTERNAL SERVER ERROR /apispec_1.json

I created a Flasgger/Swagger App in Spyder and got returned:

127.0.0.1 - - [28/Mar/2021 21:49:13] "GET /apispec_1.json HTTP/1.1" 500 -
127.0.0.1 - - [28/Mar/2021 21:49:13] "GET /flasgger_static/favicon-32x32.png HTTP/1.1" 200 -

When trying to visit this app in my Google Chrome browser via http://127.0.0.1:5000/apidocs/ I got back this error:

Fetch error
INTERNAL SERVER ERROR /apispec_1.json

What do I have to change here?

Upvotes: 2

Views: 781

Answers (1)

olepinto
olepinto

Reputation: 399

I have learned that the apispec_1.json file is generated whenever you GET apidocs. If it's not there it's because you probably have some error in any of your docstrings. I have been able to fix it

  • Running the application locally
  • Looking at the exception (see below)
  • Adding a breakpoint (pdb.set_trace(), after importing it). Once I see the offending string, remove it from the docstrings and try again, until it works.

I've been able to re-add the corrected docstrings looking at others which worked, but looking at flasgger documentation might be the proper way.

This is what I got:

... "GET /apidocs/ HTTP/1.1" 200 -
... "GET /flasgger_static/lib/jquery.min.js HTTP/1.1" 304 -
... "GET /flasgger_static/swagger-ui-standalone-preset.js HTTP/1.1" 304 -
... "GET /flasgger_static/swagger-ui-bundle.js HTTP/1.1" 304 -
... "GET /flasgger_static/swagger-ui.css HTTP/1.1" 200 -
...
Traceback (most recent call last):
  File "...\venv3.11.9\Lib\site-packages\flasgger\base.py", line 164, in get
    return jsonify(self.loader())
                   ^^^^^^^^^^^^^
  File "...\venv3.11.9\Lib\site-packages\flasgger\base.py", line 510, in get_apispecs
    defs = defs + extract_definitions(
                  ^^^^^^^^^^^^^^^^^^^^
  File "...\venv3.11.9\Lib\site-packages\flasgger\utils.py", line 789, in extract_definitions
    if not getattr(item, 'get'):
           ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'get'

In fact, I've put that line in a try/except, have it stop at the except, and seen the content of item.

Upvotes: 0

Related Questions