From dc80e779a2e708b2685fc641df99e6aae9ad6f97 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Mon, 2 Mar 2020 12:01:10 -0800 Subject: [PATCH] Handle scope path if it is a string I ran into this while running a unit test with httpx.AsyncClient --- datasette/utils/asgi.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/datasette/utils/asgi.py b/datasette/utils/asgi.py index bafcfb4a..37196b36 100644 --- a/datasette/utils/asgi.py +++ b/datasette/utils/asgi.py @@ -48,7 +48,11 @@ class Request: if "raw_path" in self.scope: return self.scope["raw_path"].decode("latin-1") else: - return self.scope["path"].decode("utf-8") + path = self.scope["path"] + if isinstance(path, str): + return path + else: + return path.decode("utf-8") @property def query_string(self):