Skip to content

Support unicode in url #558

@0x1997

Description

@0x1997

Hi, I defined some custom queries in my metadata.json. There are Chinese characters in the names of the queries. So the urls are like http://127.0.0.1:8001/mydb/测试查询.
When opening such urls, datasette will throw an exception.

Traceback (most recent call last):
  File "/home/zhe/miniconda3/lib/python3.7/site-packages/datasette/utils/asgi.py", line 100, in __call__
    return await view(new_scope, receive, send)
  File "/home/zhe/miniconda3/lib/python3.7/site-packages/datasette/utils/asgi.py", line 172, in view
    request, **scope["url_route"]["kwargs"]
  File "/home/zhe/miniconda3/lib/python3.7/site-packages/datasette/views/base.py", line 267, in get
    request, database, hash, correct_hash_provided, **kwargs
  File "/home/zhe/miniconda3/lib/python3.7/site-packages/datasette/views/base.py", line 471, in view_get
    for key in self.ds.renderers.keys()
  File "/home/zhe/miniconda3/lib/python3.7/site-packages/datasette/views/base.py", line 471, in <dictcomp>
    for key in self.ds.renderers.keys()
  File "/home/zhe/miniconda3/lib/python3.7/site-packages/datasette/utils/__init__.py", line 655, in path_with_format
    path = request.path
  File "/home/zhe/miniconda3/lib/python3.7/site-packages/datasette/utils/asgi.py", line 49, in path
    self.scope.get("raw_path", self.scope["path"].encode("latin-1"))
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 9-11: ordinal not in range(256)

This used to work when datasette was based on sanic.

Btw, thanks for the great work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions