Fuyukai / Kyoukai

[OLD] A fully async web framework for Python3.5+ using asyncio
https://mirai.veriny.tf
MIT License
298 stars 14 forks source link

Unable to track down source of a 500 #22

Closed gdude2002 closed 7 years ago

gdude2002 commented 7 years ago

Using the following code, I get a 500 on the root route (/):

# coding=utf-8
from kyoukai import Kyoukai
from kyoukai.asphalt import HTTPRequestContext

__author__ = "Gareth Coles"

app = Kyoukai("Mystic Minecraft")

@app.route("/")
async def index(ctx: HTTPRequestContext):
    return app.render_template("index.html")

if __name__ == "__main__":
    app.run()

I then attempted to add an error handler as shown in the documentation:

# coding=utf-8
from kyoukai import Kyoukai
from kyoukai.asphalt import HTTPRequestContext

__author__ = "Gareth Coles"

app = Kyoukai("Mystic Minecraft")

@app.route("/")
async def index(ctx: HTTPRequestContext):
    return app.render_template("index.html")

@app.root.errorhandler(500)
async def handle_500(ctx: HTTPRequestContext, exception_to_handle: Exception):
    return repr(exception_to_handle)

if __name__ == "__main__":
    app.run()

This results in the following exception:

Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\kyoukai\route.py", line 87, in invoke_function
    result = await result
  File "C:/Users/-gdude2002/WebStormProjects/MysticMinecraft/app.py", line 12, in index
    return app.render_template("index.html")
  File "C:\Python36\lib\site-packages\kyoukai\app.py", line 138, in __getattr__
    raise AttributeError("'{.__class__.__name__}' object has no attribute {}".format(self, item))
AttributeError: 'Kyoukai' object has no attribute render_template

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\kyoukai\app.py", line 251, in process_request
    result = await matched.invoke(ctx, params)
  File "C:\Python36\lib\site-packages\kyoukai\route.py", line 170, in invoke
    return await self.invoke_function(ctx, pre_hooks, post_hooks, **params)
  File "C:\Python36\lib\site-packages\kyoukai\route.py", line 95, in invoke_function
    raise InternalServerError() from e
werkzeug.exceptions.InternalServerError: 500: Internal Server Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\kyoukai\app.py", line 179, in handle_httpexception
    result = await error_handler.invoke(ctx, {"exc": exception})
  File "C:\Python36\lib\site-packages\kyoukai\route.py", line 160, in invoke
    self.check_route_args(params)
  File "C:\Python36\lib\site-packages\kyoukai\route.py", line 129, in check_route_args
    self._callable.__name__))
ValueError: Argument exception_to_handle not found in args for callable handle_500
INFO:Kyoukai:GET / - 500

I can also see here that render_template doesn't exist on app, which in itself seems a bit weird given what the documentation says.

Fuyukai commented 7 years ago

docs are old and outdated

also you have to explicitly name your kwarg exc in an exception handler because i am lazy and didnt figure out a nice way to handle it /shrug

will fix uh soon?

gdude2002 commented 7 years ago

The error explicitly says exception_to_handle, as do the docs, so that isn't something I would have thought of.

Fuyukai commented 7 years ago

docs are old and outdated

i should rewrite them for 2.0

also the exception is misleading, I WILL FIX THIS TOO

gdude2002 commented 7 years ago

If the docs are old, where'd the template renderer go? xD

Fuyukai commented 7 years ago

https://github.com/asphalt-framework/asphalt-templating

gdude2002 commented 7 years ago

Oh jesus, I have to use asphalt.

Well, okay, I'll give that a shot. Thanks.

gdude2002 commented 7 years ago

In setting up with Asphalt, it appears that for whatever reason the app can't be resolved, despite definitely existing there within a valid python package.

Unless you changed the config.yml directives and I'm not supposed to be using app.

It actually states that it can't resolve application.