databio / bedhost

API and UI for BEDbase
http://api.bedbase.org
BSD 2-Clause "Simplified" License
2 stars 1 forks source link

jinja2.exceptions.UndefinedError: dict object has no element 0 #2

Closed nsheff closed 5 years ago

nsheff commented 5 years ago

I can get the server to run but it shows "Internal Server Error", and the console shows this output:

python3.7 main.py
email-validator not installed, email fields will be treated as str.
To install, run: pip install email-validator
main.py:61: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  cfg = yaml.load(ymlfile)
INFO: Started server process [7228]
INFO: Waiting for application startup.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO: ('127.0.0.1', 54448) - "WebSocket /livereload" 403
INFO: ('127.0.0.1', 54452) - "GET /livereload.js?port=8000 HTTP/1.1" 404
INFO: ('127.0.0.1', 54452) - "GET / HTTP/1.1" 500
ERROR: Exception in ASGI application
Traceback (most recent call last):
  File "/home/nsheff/.local/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 375, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/home/nsheff/.local/lib/python3.7/site-packages/fastapi/applications.py", line 139, in __call__
    await super().__call__(scope, receive, send)
  File "/home/nsheff/.local/lib/python3.7/site-packages/starlette/applications.py", line 134, in __call__
    await self.error_middleware(scope, receive, send)
  File "/home/nsheff/.local/lib/python3.7/site-packages/starlette/middleware/errors.py", line 178, in __call__
    raise exc from None
  File "/home/nsheff/.local/lib/python3.7/site-packages/starlette/middleware/errors.py", line 156, in __call__
    await self.app(scope, receive, _send)
  File "/home/nsheff/.local/lib/python3.7/site-packages/starlette/exceptions.py", line 73, in __call__
    raise exc from None
  File "/home/nsheff/.local/lib/python3.7/site-packages/starlette/exceptions.py", line 62, in __call__
    await self.app(scope, receive, sender)
  File "/home/nsheff/.local/lib/python3.7/site-packages/starlette/routing.py", line 590, in __call__
    await route(scope, receive, send)
  File "/home/nsheff/.local/lib/python3.7/site-packages/starlette/routing.py", line 208, in __call__
    await self.app(scope, receive, send)
  File "/home/nsheff/.local/lib/python3.7/site-packages/starlette/routing.py", line 41, in app
    response = await func(request)
  File "/home/nsheff/.local/lib/python3.7/site-packages/fastapi/routing.py", line 111, in app
    raw_response = await dependant.call(**values)
  File "main.py", line 110, in root
    return templates.TemplateResponse("main.html", dict(vars, **ALL_VERSIONS))
  File "/home/nsheff/.local/lib/python3.7/site-packages/starlette/templating.py", line 87, in TemplateResponse
    background=background,
  File "/home/nsheff/.local/lib/python3.7/site-packages/starlette/templating.py", line 27, in __init__
    content = template.render(context)
  File "/home/nsheff/.local/lib/python3.7/site-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/home/nsheff/.local/lib/python3.7/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/home/nsheff/.local/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/nsheff/.local/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "templates/main.html", line 1, in top-level template code
    {% extends "base.html" %}
  File "templates/base.html", line 22, in top-level template code
    {% block content %}{% endblock %}
  File "templates/main.html", line 39, in block "content"
    <p>For an example bed file output, click <a href="http://localhost:8000/bedstat/{{ docs[0]._source.id[0] }}">here</a></p>
  File "/home/nsheff/.local/lib/python3.7/site-packages/jinja2/environment.py", line 430, in getattr
    return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: dict object has no element 0
INFO: ('127.0.0.1', 54456) - "GET / HTTP/1.1" 500
ERROR: Exception in ASGI application
nsheff commented 5 years ago

I think its because it's not connecting correctly to elastic, but I'm not sure why.

as an aside, can you make it print a nice message like "no regions found" instead of the error, maybe?

separately, we need to figure out why it won't connect, I must not be setting up elastic correctly...

oddodaoddo commented 5 years ago

I committed a change to dev branch that is more intelligent if there is something wrong with the elastic database, in particular, if the server is up but there is no data in the index.

oddodaoddo commented 5 years ago

https://github.com/databio/bedstat-rest-api/commit/4cf0c1c1c6edd1b60754a31b23cd5a9c0618383a

oddodaoddo commented 5 years ago

I believe this has been fixed.