Skip to content

Chapter02 Sanic Generates Error When Trying to Run src.server:app #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TheGeolama opened this issue May 4, 2022 · 4 comments
Closed

Comments

@TheGeolama
Copy link

sanic is installed in a virutalenv. Within the Chapter02/booktracker folder, I issue this command at the Windows Command prompt:

sanic src.server:app -p 7777 --debug --workers=2

I get this traceback:

Traceback (most recent call last):
File "C:\Program Files\Python310\lib\runpy.py", line 196, in _run_module_as_main
return run_code(code, main_globals, None,
File "C:\Program Files\Python310\lib\runpy.py", line 86, in run_code
exec(code, run_globals)
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\venv\Scripts\sanic.exe_main
.py", line 7, in
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\venv\lib\site-packages\sanic_main
.py", line 12, in main
cli.run()
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\venv\lib\site-packages\sanic\cli\app.py", line 82, in run
app = self._get_app()
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\venv\lib\site-packages\sanic\cli\app.py", line 135, in get_app
module = import_module(module_name)
File "C:\Program Files\Python310\lib\importlib_init
.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", line 688, in _load_unlocked
File "", line 883, in exec_module
File "", line 241, in _call_with_frames_removed
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\Chapter02\booktracker\src\server.py", line 4, in
app = create_app()
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\Chapter02\booktracker\src\utilities\app_factory.py", line 22, in create_app
autodiscover(app, *init_blueprints)
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\Chapter02\booktracker\src\utilities\autodiscovery.py", line 28, in autodiscover
app.blueprint(bp)
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\venv\lib\site-packages\sanic\app.py", line 527, in blueprint
blueprint.register(self, options)
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\venv\lib\site-packages\sanic\blueprints.py", line 357, in register
route = app._apply_route(apply_route)
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\venv\lib\site-packages\sanic\app.py", line 393, in _apply_route
routes = self.router.add(**params)
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\venv\lib\site-packages\sanic\router.py", line 137, in add
route = super().add(**params) # type: ignore
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\venv\lib\site-packages\sanic_routing\router.py", line 243, in add
group.merge(existing_group, overwrite, append)
File "D:\Development\PyCharmProjects\Python-Web-Development-with-Sanic-main\venv\lib\site-packages\sanic_routing\group.py", line 160, in merge
raise RouteExists(
sanic_routing.exceptions.RouteExists: Route already registered: book [GET]

@ahopkins
Copy link
Collaborator

ahopkins commented May 4, 2022

Thanks for bringing this up! This looks like it is the result of a change between v21.3 and v21.6 (when the chapter was written). Basically what is happening is the autodiscover is trying to load both the Blueprint and the BlueprintGroup.

I will get a correction for this up probably later today.

@TheGeolama
Copy link
Author

Still working on a fix for this?

@ahopkins
Copy link
Collaborator

ahopkins commented May 7, 2022

I just pushed a fix. In short, before we add the BlueprintGroup, we make sure to filter out any blueprints attached to it.

@ahopkins ahopkins closed this as completed May 7, 2022
@ahopkins
Copy link
Collaborator

ahopkins commented May 7, 2022

Please keep me informed of any more challenges you see. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants