PWZER / swagger-ui-py

Swagger UI for Python web framework, such Tornado, Flask and Sanic. https://pwzer.github.io/swagger-ui-py/
https://pypi.org/project/swagger-ui-py
Apache License 2.0
68 stars 31 forks source link

Bug: doesn`t work well with falcon 3.0.1 #29

Closed awardglobal closed 2 years ago

awardglobal commented 2 years ago

when i use api_doc(app, config_path='./swagger.json', url_prefix='/api/doc', title='API doc') and visit /api/doc, got 404 error

Then i tried using falcon_api_doc instead, got these error and cannot start server: Traceback (most recent call last): File "/root/customerportal/env/lib64/python3.6/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker worker.init_process() File "/root/customerportal/env/lib64/python3.6/site-packages/gunicorn/workers/base.py", line 134, in init_process self.load_wsgi() File "/root/customerportal/env/lib64/python3.6/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi self.wsgi = self.app.wsgi() File "/root/customerportal/env/lib64/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi self.callable = self.load() File "/root/customerportal/env/lib64/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 58, in load return self.load_wsgiapp() File "/root/customerportal/env/lib64/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp return util.import_app(self.app_uri) File "/root/customerportal/env/lib64/python3.6/site-packages/gunicorn/util.py", line 359, in import_app mod = importlib.import_module(module) File "/usr/lib64/python3.6/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 994, in _gcd_import File "", line 971, in _find_and_load File "", line 955, in _find_and_load_unlocked File "", line 665, in _load_unlocked File "", line 678, in exec_module File "", line 219, in _call_with_frames_removed File "/root/customerportal/app.py", line 25, in falcon_api_doc(app, config_path='./swagger.json', url_prefix='/api/doc', title='API doc') File "/root/customerportal/env/lib64/python3.6/site-packages/swagger_ui/old.py", line 37, in init super(FalconInterface, self).init(*args, **kwargs) File "/root/customerportal/env/lib64/python3.6/site-packages/swaggerui/core.py", line 36, in init getattr(self, '{}_handler'.format(app_type))() TypeError: _falcon_handler() missing 1 required positional argument: 'use_async'

loleg commented 2 years ago

I can confirm that this is indeed happening. Falcon 3.0.1 is the current release and out of the box the library does not work. Please re-open (or share the workaround :)

To me it looks like the solution is to set a default value (use_async=None or so) in https://github.com/PWZER/swagger-ui-py/blob/master/swagger_ui/core.py#L238

See also #26

PWZER commented 2 years ago

@awardglobal Get 404 error, you can see How does Falcon handle a trailing slash in the request path?

PWZER commented 2 years ago

@loleg swagger-ui-py version?Can you give me the replay code?

loleg commented 2 years ago

@PWZER sure:

$ python api.py
Traceback (most recent call last):
  File ".../api.py", line 88, in <module>
    falcon_api_doc(app, config=spec.to_dict(), url_prefix='/api/doc/', title='API doc')
  File "/home/oleg/.cache/pypoetry/virtualenvs/ecohabitasopen-xwr1MByN-py3.9/lib/python3.9/site-packages/swagger_ui/old.py", line 37, in __init__
    super(FalconInterface, self).__init__(*args, **kwargs)
  File "/home/oleg/.cache/pypoetry/virtualenvs/ecohabitasopen-xwr1MByN-py3.9/lib/python3.9/site-packages/swagger_ui/core.py", line 36, in __init__
    getattr(self, '_{}_handler'.format(app_type))()
TypeError: _falcon_handler() missing 1 required positional argument: 'use_async'

This is with swagger-ui-py version 0.4.1

PWZER commented 2 years ago

@loleg @awardglobal The problem has been fixed,You can try the updated version use pip.