emmett-framework / granian

A Rust HTTP server for Python applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UnicodeEncodeError when handling URLs with Unicode characters

blazstefin opened this issue · comments

I'm developing a Django application with Granian as the ASGI server. I've encountered a UnicodeEncodeError when handling URLs that include Unicode characters. This issue specifically occurs when sending requests to URLs containing non-ASCII characters. For example, accessing /en/bookings/buoy_availability/LU%C4%8C28/ triggers the error.

Error message

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/granian/_futures.py", line 4, in future_watcher
    await inner(watcher.scope, watcher.proto)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/granian/asgi.py", line 110, in wrapper
    return callback(scope.as_dict(root_url_path, state.copy()), proto.receive, proto.send)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'ascii' codec can't encode character '\u010c' in position 33: ordinal not in range(128)

Expected vs. Actual Behavior:
I expect the application to handle URLs with Unicode characters seamlessly, as it does when I use Django's development server with runserver. However, when running under Granian, it fails with the mentioned UnicodeEncodeError.

Steps to Reproduce:

  1. Define a URL pattern that includes Unicode characters or accepts them as parameters.
  2. Attempt to access a URL that matches the pattern and includes Unicode characters.