sanic-org / sanic-openapi

Easily document your Sanic API with a UI
https://sanic-openapi.readthedocs.io/
MIT License
505 stars 108 forks source link

Route already registered: /swagger/<file_uri:/?.+> [GET,HEAD] #225

Closed chongtwo closed 3 years ago

chongtwo commented 3 years ago

sanic 20.12.2 sanci-openapi 0.6.2 centos 7.4

When I run my project through pycharm all work fine, but when I package my project through pyinstaller and try to run the exe it cracks with the message that

File "sanic/app.py", line 718, in blueprint   
File "sanic/blueprints.py", line 151, in register   
File "sanic/app.py", line 696, in static   
File "sanic/static.py", line 175, in register   
File "sanic/app.py", line 217, in response  
File "sanic/router.py", line 158, in add   
File "sanic/router.py", line 317, in _add   
File "sanic/router.py", line 268, in merge_route
sanic.router.RouteExists: Route already registered: /swagger/<file_uri:/?.+> [GET,HEAD]

I have seen #216 but it doesn't seem to help.

artcg commented 3 years ago

Thanks for the report, i don't know about this one but one thing I can see which might help you is that your sanic version is outdated, could try version 20.12.3 which is the latest from the 2012 release,

would also recommend to try with sanic 18.12 and sanic 21.3 and see if either of those work

if not i could help you debug it if you share a small code sample which can recreate it

artcg commented 3 years ago

Will close this but please do re-open if that doesn't solve your problem

chongtwo commented 3 years ago

I've tried your suggestion but it didn't work. The code is as below:

# sanic-openapi-test.py
from sanic import Sanic
from sanic.response import json
from sanic_openapi import swagger_blueprint

app = Sanic(name="sanic_openapi_test")
app.blueprint(swagger_blueprint)

@app.route("/")
async def test(request):
    return json({"hello": "world"})

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8000)

And I packaged the code by PyInstaller (pip install pyinstaller)

 pyinstaller sanic-openapi-test.py

Went into the dist directory that is made by the command above and ran the sanic_openapi_test.exe. The error appeared:

Traceback (most recent call last):
  File "sanic_openapi_test.py", line 6, in <module>
  File "sanic\app.py", line 421, in blueprint
  File "sanic\blueprints.py", line 234, in register
  File "sanic\app.py", line 345, in _apply_static
  File "sanic\mixins\routes.py", line 803, in _register_static
  File "sanic\mixins\routes.py", line 155, in decorator
  File "sanic\app.py", line 335, in _apply_route
  File "sanic\router.py", line 128, in add
  File "sanic_routing\router.py", line 170, in add
  File "sanic_routing\route.py", line 115, in add_handler
sanic_routing.exceptions.RouteExists: Route already registered: swagger/<__file_uri__> [GET]
[6444] Failed to execute script sanic_openapi_test

Hope you can help me solve this problem. Thanks!