Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support unicode in url #558

Closed
0x1997 opened this issue Jul 12, 2019 · 4 comments

Comments

@0x1997
Copy link

commented Jul 12, 2019

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!

@simonw

This comment has been minimized.

Copy link
Owner

commented Jul 12, 2019

Thanks, this is really useful feedback. I'll take a look at this and see if I can figure out how the new ASGI/Uvicorn stuff differs from Sanic here.

@simonw simonw added the bug label Jul 12, 2019

@simonw

This comment has been minimized.

Copy link
Owner

commented Jul 12, 2019

Are you definitely running the most recent release of uvicorn? The raw_path ASGI variable is only available in 0.8.1 or later.

@simonw simonw closed this in 90d4f49 Jul 14, 2019

@simonw

This comment has been minimized.

@0x1997

This comment has been minimized.

Copy link
Author

commented Jul 15, 2019

Thanks, the latest version works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.