ahmetoner / whisper-asr-webservice

OpenAI Whisper ASR Webservice API
https://ahmetoner.github.io/whisper-asr-webservice
MIT License
2.15k stars 383 forks source link

UnicodeEncodeError: 'latin-1' codec can't encode character '\u0119' in position 61: ordinal not in range(256) #187

Open ordigital opened 10 months ago

ordigital commented 10 months ago

Error 500 after using /asr endpoint with polish language.

[2024-01-13 14:33:35 +0000] [28] [ERROR] Exception in ASGI application
Traceback (most recent call last):
  File "/app/.venv/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 426, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/app/.venv/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
    return await self.app(scope, receive, send)
  File "/app/.venv/lib/python3.10/site-packages/fastapi/applications.py", line 1106, in __call__
    await super().__call__(scope, receive, send)
  File "/app/.venv/lib/python3.10/site-packages/starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/app/.venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/app/.venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/app/.venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/app/.venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/app/.venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 20, in __call__
    raise e
  File "/app/.venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 17, in __call__
    await self.app(scope, receive, send)
  File "/app/.venv/lib/python3.10/site-packages/starlette/routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "/app/.venv/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/app/.venv/lib/python3.10/site-packages/starlette/routing.py", line 66, in app
    response = await func(request)
  File "/app/.venv/lib/python3.10/site-packages/fastapi/routing.py", line 274, in app
    raw_response = await run_endpoint_function(
  File "/app/.venv/lib/python3.10/site-packages/fastapi/routing.py", line 191, in run_endpoint_function
    return await dependant.call(**values)
  File "/app/app/webservice.py", line 76, in asr
    return StreamingResponse(
  File "/app/.venv/lib/python3.10/site-packages/starlette/responses.py", line 246, in __init__
    self.init_headers(headers)
  File "/app/.venv/lib/python3.10/site-packages/starlette/responses.py", line 73, in init_headers
    raw_headers = [
  File "/app/.venv/lib/python3.10/site-packages/starlette/responses.py", line 74, in <listcomp>
    (k.lower().encode("latin-1"), v.encode("latin-1"))
UnicodeEncodeError: 'latin-1' codec can't encode character '\u0119' in position 61: ordinal not in range(256)

Solution

Seems to be scarlette's problem with encoding headers in latin-1 instead of utf-8: https://github.com/encode/starlette/issues/790

It can ber solved by adding new version of starlette to pip install in Dockerfile:

    && $POETRY_VENV/bin/pip install fastapi==0.109.0 --no-deps \
    && $POETRY_VENV/bin/pip install starlette==0.35.1 --no-deps

Requirements for whisper-asr-webservice should be updated with those packages versions.

disconnect5852 commented 10 months ago

same here:

[2024-01-15 19:19:22 +0000] [7] [ERROR] Exception in ASGI application
Traceback (most recent call last):
  File "/app/.venv/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 426, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/app/.venv/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
    return await self.app(scope, receive, send)
  File "/app/.venv/lib/python3.10/site-packages/fastapi/applications.py", line 1106, in __call__
    await super().__call__(scope, receive, send)
  File "/app/.venv/lib/python3.10/site-packages/starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/app/.venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/app/.venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/app/.venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/app/.venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/app/.venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 20, in __call__
    raise e
  File "/app/.venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 17, in __call__
    await self.app(scope, receive, send)
  File "/app/.venv/lib/python3.10/site-packages/starlette/routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "/app/.venv/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/app/.venv/lib/python3.10/site-packages/starlette/routing.py", line 66, in app
    response = await func(request)
  File "/app/.venv/lib/python3.10/site-packages/fastapi/routing.py", line 274, in app
    raw_response = await run_endpoint_function(
  File "/app/.venv/lib/python3.10/site-packages/fastapi/routing.py", line 191, in run_endpoint_function
    return await dependant.call(**values)
  File "/app/app/webservice.py", line 76, in asr
    return StreamingResponse(
  File "/app/.venv/lib/python3.10/site-packages/starlette/responses.py", line 246, in __init__
    self.init_headers(headers)
  File "/app/.venv/lib/python3.10/site-packages/starlette/responses.py", line 73, in init_headers
    raw_headers = [
  File "/app/.venv/lib/python3.10/site-packages/starlette/responses.py", line 74, in <listcomp>
    (k.lower().encode("latin-1"), v.encode("latin-1"))
UnicodeEncodeError: 'latin-1' codec can't encode character '\u0171' in position 51: ordinal not in range(256)
livehl commented 10 months ago

文件名不要包含中文。把文件名改成英文即可。