Skip to content

[Bug]: WebGear throws error 500: context must include a "request" key #403

Description

@lorenzo-frittoli

Description

I am using the example code for WebGear on a RaspberryPi. The code works fine on my Debian 12 machine, it breaks on the rpi.
Here is what I see on the page:
image

Issue Checklist

  • I have searched open or closed issues for my problem and found nothing related or helpful.
  • I have read the Documentation and found nothing related to my problem.
  • I've read the Issue Guidelines and wholeheartedly agree.

Expected behaviour

I'd like for the page to load the video and stream properly.

Actual behaviour

It errors as described above.

Steps to reproduce

Install testing branch + dependencies and run the python code.
Here is the video I was using. I don't think it's relevant, but it is very cute.
https://github.com/abhiTronix/vidgear/assets/95591833/87e3dc84-4a02-418e-b617-3f0ec318ba27

Terminal log output

21:40:59 ::    Helper     ::   INFO   :: Running VidGear Version: 0.3.3
21:40:59 :: Helper_Async  ::  DEBUG   :: Found valid WebGear data-files successfully.
21:40:59 ::    WebGear    ::  DEBUG   :: `/home/pi/.vidgear/webgear` is the default location for saving WebGear data-files.
21:40:59 ::    CamGear    ::  DEBUG   :: Enabling Threaded Queue Mode for the current video source!
21:40:59 ::    WebGear    ::  DEBUG   :: Enabling JPEG Frame-Compression with Colorspace:`BGR`, Quality:`80`%, Fastdct:`enabled`, and Fastupsample:`disabled`.
21:40:59 ::    WebGear    ::  DEBUG   :: Initiating Video Streaming.
21:40:59 ::    WebGear    ::  DEBUG   :: Running Starlette application.
INFO:     Started server process [77467]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://raspberrypi.local:8000 (Press CTRL+C to quit)
INFO:     172.20.10.4:48988 - "GET / HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/uvicorn/protocols/http/h11_impl.py", line 366, in run_asgi
    result = await app(self.scope, self.receive, self.send)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/lib/python3/dist-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/usr/lib/python3/dist-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/usr/lib/python3/dist-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/usr/lib/python3/dist-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/usr/lib/python3/dist-packages/starlette/routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "/usr/lib/python3/dist-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/usr/lib/python3/dist-packages/starlette/routing.py", line 66, in app
    response = await func(request)
               ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/vidgear-0.3.3-py3.11.egg/vidgear/gears/asyncio/webgear.py", line 505, in __homepage
    self.__templates.TemplateResponse(request, "index.html")
  File "/usr/lib/python3/dist-packages/starlette/templating.py", line 106, in TemplateResponse
    raise ValueError('context must include a "request" key')
ValueError: context must include a "request" key
INFO:     172.20.10.4:48994 - "GET /favicon.ico HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/usr/lib/python3/dist-packages/starlette/routing.py", line 747, in __call__
    await self.default(scope, receive, send)
  File "/usr/lib/python3/dist-packages/starlette/routing.py", line 635, in not_found
    raise HTTPException(status_code=404)
starlette.exceptions.HTTPException

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/uvicorn/protocols/http/h11_impl.py", line 366, in run_asgi
    result = await app(self.scope, self.receive, self.send)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/lib/python3/dist-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/usr/lib/python3/dist-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/usr/lib/python3/dist-packages/starlette/middleware/exceptions.py", line 88, in __call__
    response = await handler(request, exc)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/vidgear-0.3.3-py3.11.egg/vidgear/gears/asyncio/webgear.py", line 518, in __not_found
    self.__templates.TemplateResponse(request, "404.html", status_code=404)
  File "/usr/lib/python3/dist-packages/starlette/templating.py", line 106, in TemplateResponse
    raise ValueError('context must include a "request" key')
ValueError: context must include a "request" key

Python Code(Optional)

# import required libraries
import uvicorn
from vidgear.gears.asyncio import WebGear

# various performance tweaks
options = {
    "frame_size_reduction": 40,
    "jpeg_compression_quality": 80,
    "jpeg_compression_fastdct": True,
    "jpeg_compression_fastupsample": False,
}

# initialize WebGear app
web = WebGear(source="catvideo.mp4", logging=True, **options)

# run this app on Uvicorn server at address http://localhost:8000/
uvicorn.run(web(), host="172.20.10.4", port=8000)

# close app safely
web.shutdown()

VidGear Version

testing

Python version

3.11.2

OpenCV version

4.10.0

Operating System version

raspian (aka Debian 12 Bookworm)

Any other Relevant Information?

This happens only if I host on the rpi if I try to access the webpage from any device on the network.
Sorry to bother, this is probably a silly mistake on my part - enjoy the cat video as compensation.

Activity

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

Metadata

Metadata

Assignees

Labels

BUG 🐛Vidgear api's error, flaw or faultSOLVED 🏁This issue/PR is resolved now. Goal Achieved!

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions